小弟日前於網路上學習碰到一隻程式
想請問其中isEmpty()是在檢查什麼為Empty呢?
是指root這個變數未經過初始化嗎?
不好意思基礎不太好, 麻煩各位解答了, 感謝!
public class Binary_Tree {
BinaryTreeNode root = null;
static ArrayList array_list = new ArrayList();
public static void main(String[] args) {
Binary_Tree by = new Binary_Tree();
by.insert(24);
by.insert(58);
by.insert(33);
by.insert(19);
by.insert(6);
by.insert(39);
by.insert(19);
by.print();
by.search(array_list, 19);
}
public void insert(int data) {
BinaryTreeNode newNode = new BinaryTreeNode(data);
if(isEmpty())
root = newNode;
else
root.insert(newNode);
}
public void print(){
if(isEmpty())
System.out.print("no data");
else
root.print();
}
.....
.....
.....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.162.21