關於我自己

我的相片
Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu

最新消息

總網頁瀏覽量

2009年5月14日 星期四

第十二週

第十二週

fig. 19.17 tree.java
http://www.cis.temple.edu/~ingargio/cis67/software/deitel-jHTP4/ch19/

http://www.google.com.tw/search?hl=zh-TW&q=fig.+19.17+tree.java&btnG=%E6%90%9C%E5%B0%8B&meta=&aq=f&oq=
http://www.cis.temple.edu/~ingargio/cis67/software/deitel-jHTP4/ch19/



http://users.cs.fiu.edu/~weiss/dsj3/code/

ArrayList members to binary tree nodes
http://forums.sun.com/thread.jspa?threadID=5373085

http://forums.sun.com/thread.jspa?threadID=5381791

1 則留言:

HPS 提到...

//第十二週 D9539125 黃培熏
class HPS_Tree
{
TreeNode root;

HPS_Tree()
{
root = null;
}

void InsertNode(int InsertValue)
{
if (root == null)
root = new TreeNode(InsertValue);

else
root.insert(InsertValue);
}

void PreorderTraversal()
{
PreorderHelper(root);
}

void PreorderHelper(TreeNode node)
{
//沒有資料就跳出
if (node == null)
{
System.out.println("\nnull");
return;
}
else
{
System.out.println("\nnon-null");
//輸出資料
System.out.print(node.data + " ");
//左節點
PreorderHelper(node.leftNode);
//右節點
PreorderHelper(node.rightNode);
}
}

void IneorderTraversal()
{
InorderHelper(root);
}

void InorderHelper(TreeNode node)
{
//沒有資料就跳出
if (node == null)
return;
//左節點
InorderHelper(node.leftNode);
//輸出資料
System.out.print(node.data + " ");
//右節點
InorderHelper(node.rightNode);
}

void PosteorderTraversal()
{
PostorderHelper(root);
}

void PostorderHelper(TreeNode node)
{
//沒有資料就跳出
if (node == null)
return;
//左節點
PostorderHelper(node.leftNode);
//右節點
PostorderHelper(node.rightNode);
//輸出資料
System.out.print(node.data + " ");
}

public static void main(String[] args)
{
HPS_Tree tree = new HPS_Tree();
tree.PreorderTraversal();
tree.InsertNode(47);
tree.InsertNode(77);
tree.InsertNode(25);
tree.PreorderTraversal();
}

}