由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 有简洁树代码么
相关主题
弱问一个数据结构binary tree的in-order iterator怎么写?
问一个问题: binary search Tree的删除用java实现。BinaryTree to DoublyLinkedList
请教各位大牛一个K-way merge 的问题弱问:不好意思,这个CODE问题在哪里?
刚才的amazon phone interview 第一轮写了一下leetcode上Valid Number,用boolean表示一些状态是不是比较简单
题目: iterative binary tree post order traversal这个check whether a binary tree is a BST or not
Tree Question: Longest path from root to a leaf新鲜Amazon面经(附参考答案) 顺便求各种大公司refer
谷歌 电面"Hacking a G Interview"怎么有这样低级错?
A onsite被拒,面经,求分析失败原因弱问怎么判断两个binary tree相同?
相关话题的讨论汇总
话题: binarytree话题: key话题: data话题: int话题: searchkey
进入JobHunting版参与讨论
1 (共1页)
y***m
发帖数: 7027
1
这个简单java的,有更简洁明了完善高效结构化的么,thx!
class BinaryTree {
private int data;
private int minNode = Integer.MAX_VALUE;
private BinaryTree leftpoiter;
private BinaryTree rightpoiter;
public BinaryTree() {
}
public BinaryTree(int data) {
this.data = data;
leftpoiter = null;
rightpoiter = null;
}
public void getMinNode(int key) {
getMinNode(this, key);
}
public void getMinNode(BinaryTree root, int key) {
if (root != null) {
if (root.data > key) {
minNode = (root.data < minNode) ? root.data : minNode;
getMinNode(root.leftpoiter, key);
} else
getMinNode(root.rightpoiter, key);
}
}
public boolean searchkey(int key) {
return searchkey(this, key);
}
public boolean searchkey(BinaryTree root, int key) {
if (root == null)
return false;
else if (root.data == key)
return true;
else if (key >= root.data)
return searchkey(root.rightpoiter, key);
return searchkey(root.leftpoiter, key);
}
public void createTree(int data[]) {
this.data = data[0];
for (int i = 1; i < data.length; i++) {
this.insertTree(this, data[i]);
}
}
public void insertTree(BinaryTree root, int data) {
if (data >= root.data) {
if (root.rightpoiter == null)
root.rightpoiter = new BinaryTree(data);
else
insertTree(root.rightpoiter, data);
} else {
if (root.leftpoiter == null)
root.leftpoiter = new BinaryTree(data);
else
insertTree(root.leftpoiter, data);
}
}
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
弱问怎么判断两个binary tree相同?题目: iterative binary tree post order traversal
一个JAVA语法问题Tree Question: Longest path from root to a leaf
问一个leetcode上Validate Binary Search Tree的问题谷歌 电面
请问个算法复杂度A onsite被拒,面经,求分析失败原因
弱问一个数据结构binary tree的in-order iterator怎么写?
问一个问题: binary search Tree的删除用java实现。BinaryTree to DoublyLinkedList
请教各位大牛一个K-way merge 的问题弱问:不好意思,这个CODE问题在哪里?
刚才的amazon phone interview 第一轮写了一下leetcode上Valid Number,用boolean表示一些状态是不是比较简单
相关话题的讨论汇总
话题: binarytree话题: key话题: data话题: int话题: searchkey