關於我自己

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

最新消息

總瀏覽量

2009年5月22日 星期五

第十三週

第十三週

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


//=====================================================================
教學錄影
http://www.powercam.cc/slide/1615

//=====================================================================



class Mytreeone
{
TreeNode root;


Mytreeone()
{
//root=null;

}


void preorderTravel()
{
preorderHelper(root);
}
void preorderHelper(TreeNode node)
{
if(node==null)
return;
System.out.println(node.data);
preorderHelper(node.leftNode);
preorderHelper(node.rightNode);
}

void inoderTravel()
{
inoderHelper(root);
}
void inoderHelper(TreeNode node)
{
if(node==null)
return;
inoderHelper(node.leftNode);
System.out.println(node.data);
inoderHelper(node.rightNode);


}


void postorderTravel()
{
postorderHelper(root);
}
void postorderHelper(TreeNode node)
{
if(node==null)
return;
postorderHelper(node.leftNode);
postorderHelper(node.rightNode);
System.out.println(node.data);


}














void insertNode(int insertvalue)
{
if (root==null )
{

root=new TreeNode(insertvalue);
}
else
{

root.insert(insertvalue);

}


}
public static void main(String args[])
{
Mytreeone tree=new Mytreeone();

tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);

tree.preorderTravel();
System.out.println("==========");
tree.inoderTravel();
System.out.println("==========");
tree.postorderTravel();
}
}

8 則留言:

歐地 提到...

//第十三週 D9539125 黃培熏
class HPS_TreeTest
{
TreeNode root;

HPS_TreeTest()
{
root = null;
}
//===================================//
//中序
void InOrder()
{
InOrderHelper(root);
}
//中序的疊代
void InOrderHelper(TreeNode node)
{
if (node == null)
return;
InOrderHelper(node.leftNode);
System.out.print(node.data + " ");
InOrderHelper(node.rightNode);
}
//===================================//
//前序
void PreOrder()
{
PreOrderHelper(root);
}
//前序的疊代
void PreOrderHelper(TreeNode node)
{
if (node == null)
return;
System.out.print(node.data + " ");
PreOrderHelper(node.leftNode);
PreOrderHelper(node.rightNode);
}
//===================================//
//後序
void PostOrder()
{
PostOrderHelper(root);
}
//後序的疊代
void PostOrderHelper(TreeNode node)
{
if (node == null)
return;
PostOrderHelper(node.leftNode);
PostOrderHelper(node.rightNode);
System.out.print(node.data+" ");
}
//===================================//
//新增
void InsertNode(int InsertValue)
{
if (root == null)
{
root = new TreeNode(InsertValue);
}
else
{
root.insert(InsertValue);
}
}
//===================================//
//程式進入點
public static void main(String[] args)
{
HPS_TreeTest tree = new HPS_TreeTest();
tree.InsertNode(47);
tree.InsertNode(77);
tree.InsertNode(25);
tree.InsertNode(11);
tree.InsertNode(43);
tree.InsertNode(65);
tree.InsertNode(93);
tree.InsertNode(7);
tree.InsertNode(17);
tree.InsertNode(31);
tree.InsertNode(44);
tree.InsertNode(68);
System.out.println("中序");
tree.InOrder();
System.out.println("\n前序");
tree.PreOrder();
System.out.println("\n後序");
tree.PostOrder();
}

}

1 提到...

/*0522 JAVA 陸靖文 D9539108*/

class BBBTree{
TreeNode root;

BBBTree(){
root=null;
}

void InorderTravel(){
InorderTravelHelper(root);
}

void InorderTravelHelper(TreeNode node){
if (node == null)
return;
InorderTravelHelper(node.leftNode);
System.out.print(node.data+" ");
InorderTravelHelper(node.rightNode);
}


void PreorderTravel()
{
PreorderTravelHelper(root);
}
void PreorderTravelHelper(TreeNode node)
{
if (node == null)
return;
System.out.print(node.data + " ");
PreorderTravelHelper(node.leftNode);
PreorderTravelHelper(node.rightNode);
}


void PostorderTravel()
{
PostorderTravelHelper(root);
}
void PostorderTravelHelper(TreeNode node)
{
if (node == null)
return;
PostorderTravelHelper(node.leftNode);
PostorderTravelHelper(node.rightNode);
System.out.print(node.data + " ");
}

void InsertNode(int insertValue){
if (root==null){
root = new TreeNode(insertValue);
}
else{
root.insert(insertValue);
}
}

public static void main(String args[]){
BBBTree tree = new BBBTree();
tree.InsertNode(47);
tree.InsertNode(25);
tree.InsertNode(77);
tree.InsertNode(11);
tree.InsertNode(43);
tree.InsertNode(65);
tree.InsertNode(93);
tree.InsertNode(7);
tree.InsertNode(17);
tree.InsertNode(31);
tree.InsertNode(44);
tree.InsertNode(68);

System.out.println("中序");
tree.InorderTravel();
System.out.println("\n前序");
tree.PreorderTravel();
System.out.println("\n後序");
tree.PostorderTravel();
}
}

提到...

//D9476995 辛為儒
class Mytreeone{

TreeNode root;

Mytreeone(){
root = null;
}
// ===========Inorder中序排法===============
void inorderTraveral(){
inorderHelper(root);
}
void inorderHelper(TreeNode node){
if(node == null){
return;}
inorderHelper(node.leftNode);
System.out.println(node.data);
inorderHelper(node.rightNode);
}
// ===========Preorder前序排法===============
void preorderTraveral(){
preorderHelper(root);
}
void preorderHelper(TreeNode node){
if(node == null){
return;}
System.out.println(node.data);
preorderHelper(node.leftNode);
preorderHelper(node.rightNode);
}
// ===========Postorder後序排法===============
void postorderTraveral(){
postorderHelper(root);
}
void postorderHelper(TreeNode node){
if(node == null){
return;}
postorderHelper(node.leftNode);
postorderHelper(node.rightNode);
System.out.println(node.data);
}


void insertNode(int insertValue){

if(root == null){
root = new TreeNode(insertValue);
//System.out.println(insertValue);
}
else{
//System.out.println(insertValue);
root.insert(insertValue);
}
}

public static void main(String args[]){

Mytreeone tree = new Mytreeone();
tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(45);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);

System.out.println("中序排法");
tree.inorderTraveral();
System.out.println("前序排法");
tree.preorderTraveral();
System.out.println("後序排法");
tree.postorderTraveral();


}

}

dragon 提到...

/*d9582608*/
class dragon
{
TreeNode root;
dragon ()
{
root=null;
}
void preororderTravel()
{
preororderHelper(root);
}
void preororderHelper(TreeNode node)
{
if (node == null)
return;
System.out.println(node.data);
preororderHelper(node.leftNode);
preororderHelper(node.rightNode);
}
void inorderTravel()
{
inorderHelper(root);
}
void inorderHelper(TreeNode node)
{
if (node == null)
return;
inorderHelper(node.leftNode);
System.out.println(node.data);
inorderHelper(node.rightNode);
}
void postorderTravel()
{
postorderHelper(root);
}
void postorderHelper(TreeNode node)
{
if (node == null)
return;
postorderHelper(node.leftNode);
postorderHelper(node.rightNode);
System.out.println(node.data);
}
void insertNode(int insertvalue)
{
if(root == null)
{
root = new TreeNode(insertvalue);
}
else
{
root.insert(insertvalue);
}
}
public static void main(String args[])
{
dragon tree = new dragon();
tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);
System.out.println("前序");
tree.preororderTravel();
System.out.println("中序");
tree.inorderTravel();
System.out.println("後序");
tree.postorderTravel();
}
}

提到...

//D9476668陳秋宇

class Mytreeone{


TreeNode root;


Mytreeone()
{
//root=null;
}


void preorderTravel()
{
preorderHelper(root);
}
void preorderHelper(TreeNode node)
{
if(node==null)
return;
System.out.println(node.data);
preorderHelper(node.leftNode);
preorderHelper(node.rightNode);
}



void inorderTravel()
{
inorderHelper(root);
}
void inorderHelper(TreeNode node)
{
if(node==null)
return;
inorderHelper(node.leftNode);
System.out.println(node.data);
inorderHelper(node.rightNode);
}


void postorderTravel()
{
postorderHelper(root);
}
void postorderHelper(TreeNode node)
{
if(node==null)
return;

postorderHelper(node.leftNode);
postorderHelper(node.rightNode);
System.out.println(node.data);
}

void insertNode(int insertvalue)
{
if(root==null)
{
root = new TreeNode(insertvalue);
}
else
{

root.insert(insertvalue);
}



}

public static void main(String args[]){

Mytreeone tree=new Mytreeone();
tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);
System.out.println("中序");
tree.inorderTravel();
System.out.println("\n前序");
tree.preorderTravel();
System.out.println("\n後序");
tree.postorderTravel();


}


}

radrops 提到...

//D9582256 高岱群
class Ratreeone
{
TreeNode root;

//-----------------------------------------------------
void preorderTavid()
{
System.out.println("前序");
preorderHelp(root);
}

void preorderHelp(TreeNode node)
{
if(node==null)
return;


System.out.println(node.data);
inorderHelp(node.leftNode);
inorderHelp(node.rightNode);
}
//-----------------------------------------------------
void inorderTavid()
{
System.out.println("中序");
inorderHelp(root);
}

void inorderHelp(TreeNode node)
{
if(node==null)
return;


inorderHelp(node.leftNode);
System.out.println(node.data);
inorderHelp(node.rightNode);
}
//----------------------------------------------------------
void postorderTavid()
{
System.out.println("後序");
postorderHelp(root);
}

void postorderHelp(TreeNode node)
{
if(node==null)
return;


inorderHelp(node.leftNode);
inorderHelp(node.rightNode);
System.out.println(node.data);
}
//-----------------------------------------------------

Ratreeone()
{
root=null;
}
void insertNode(int insertvalue)
{

if(root==null)
{

root=new TreeNode(insertvalue);
}
else
{
root.insert(insertvalue);

}
}

public static void main(String []args)
{
Ratreeone tree=new Ratreeone();

tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);

tree.preorderTavid();
tree.inorderTavid();
tree.postorderTavid();
}
}

提到...

劉羽程
----------------------------------
class mytreeone
{
TreeNode root;
mytreeone()
{
root=null;
}
void inorderTraval()
{
inorderHelper(root);
}
void inorderHelper(TreeNode node)
{
if(node==null)
return;
inorderHelper(node.leftNode);
System.out.println(node.data);
inorderHelper(node.rightNode);
}
void preorderTraval()
{
preorderHelper(root);
}
void preorderHelper(TreeNode node)
{
if(node==null)
return;
System.out.println(node.data);
preorderHelper(node.leftNode);
preorderHelper(node.rightNode);
}
void postorderTraval()
{
postorderHelper(root);
}
void postorderHelper(TreeNode node)
{
if(node==null)
return;
postorderHelper(node.leftNode);
postorderHelper(node.rightNode);
System.out.println(node.data);
}
void insertNode(int insertvalue)
{
if (root==null)
{
root=new TreeNode(insertvalue);
}
else
{
root.insert(insertvalue);
}
}
public static void main(String args[])
{
mytreeone tree = new mytreeone();
tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);
System.out.println("前序");
tree.preorderTraval();
System.out.println("中序");
tree.inorderTraval();
System.out.println("後序");
tree.postorderTraval();
}
}

乃爸 提到...

//應數三甲D9538864 徐晟哲
import java.util.Scanner;
class Mytreeone
{
TreeNode root;


Mytreeone()
{
root=null;
}

void orderTravwesal()
{
System.out.println("中序");

orderHeleper(root);
System.out.println("-----------------------------");

}


void orderHeleper(TreeNode node)
{
if(node==null){
return;
}
orderHeleper(node.leftNode);
System.out.println(node.data);
orderHeleper(node.rightNode);
}


void preorderTravwesal()
{
System.out.println("前序");

preorderHeleper(root);
System.out.println("-----------------------------");
}
void preorderHeleper(TreeNode node)
{


if(node==null){
return;
}

System.out.println(node.data);
preorderHeleper(node.leftNode);
preorderHeleper(node.rightNode);
}

void postorderTravwesal()
{
System.out.println("後序");

postorderHeleper(root);
System.out.println("-----------------------------");
}
void postorderHeleper(TreeNode node)
{


if(node==null){
return;
}
postorderHeleper(node.leftNode);
postorderHeleper(node.rightNode);
System.out.println(node.data);

}



void insertNode(int insertvalue)
{
if (root==null)
{
root = new TreeNode(insertvalue);
}
else
{
root.insert( insertvalue );
}
}


public static void main(String args[])
{
Mytreeone tree = new Mytreeone();

tree.insertNode(47);
tree.insertNode(25);
tree.insertNode(77);
tree.insertNode(11);
tree.insertNode(43);
tree.insertNode(65);
tree.insertNode(93);
tree.insertNode(7);
tree.insertNode(17);
tree.insertNode(31);
tree.insertNode(44);
tree.insertNode(68);
tree.orderTravwesal();
tree.preorderTravwesal();
tree.postorderTravwesal();
}

}