第十二週
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
許老師結合數學與電腦程式的教學網 課程包含 程式設計 數值分析 -------------------------------------- Prof. Hsu teaches computer programming and numerical analysis to help those who wants to be a computer programming master and focus on controlling computers to benefit people more than only on making money.
關於我自己
- 許志宇(Chih-Yu Hsu)
- Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu
1 則留言:
//第十二週 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();
}
}
張貼留言