java - Java中的两层通用结构
问题描述
我想让一个二叉树将节点保持为堆,以便我尝试在泛型中创建一个泛型,但我遇到了一些问题。
1-)我想不出两层通用在Java中是否可行。
2-)我将树添加为数字,但是当我尝试返回节点时,我现在没有分配什么,如果可以返回,我可以达到它的方法。
二叉搜索树堆树
public class BSTHeapTree <E extends Comparable<? extends Comparable<?>>>{
BinarySearchTree<E<T>> root; //error
public BSTHeapTree() {
root = new BinarySearchTree<>(); // error
}
int add(E _data) {
= root.getRoot(); //Assign what
return 0;
}
}
二叉搜索树
public class BinarySearchTree<E extends Comparable<E>>{
private Node<E> head;
public BinarySearchTree() {
head = null;
}
public Node<E> getRoot() {
return head;
}
private static class Node<E extends Comparable<E>>{
E data;
Node<E> lBranch;
Node<E> rBranch;
}
}
堆
public class Heap<E extends Comparable<E>> implements Comparable<Heap<E>>{
private E[] heapData;
}
解决方案
推荐阅读
- python-3.x - 添加将 docplex 链接到 python3 的路径
- javascript - 无法更改 AngularJS 上的范围变量值
- python-3.x - 如何将多级索引行转换为多级索引列?
- java - 在 SQL 中获取多个计数
- java - Java Microstream - ImmutablePair 导致 PersistenceExceptionTypeNotPersistable
- node.js - NodeJS:从公共 Tableau 表中获取数据
- c# - 尝试加载到字符串时出现一些奇怪的 XML 问题
- python - 在另一个图像上匹配轮廓或绘制 (png) 轮廓
- java - 有没有办法使用 EasyMock/PowerMock 测试 JUnit 测试中从不使用默认时区?
- grep - grep 输入文件中的确切单词