†Asian Ins†i†u†e Of Compu†er Studies†
†Asian Ins†i†u†e Of Compu†er Studies†

Binary Tree Downlo10
Please Register To Log in...
†Asian Ins†i†u†e Of Compu†er Studies†
†Asian Ins†i†u†e Of Compu†er Studies†

Binary Tree Downlo10
Please Register To Log in...
†Asian Ins†i†u†e Of Compu†er Studies†
Would you like to react to this message? Create an account in a few clicks or log in to continue.

†Asian Ins†i†u†e Of Compu†er Studies†


 
HomeGalleryLatest imagesSearchRegisterLog in
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
†AE1DA†MixPOD†

Latest topics
» JAVA CALCULATE
Binary Tree I_icon_minitimeMon Sep 17, 2012 2:14 pm by †`Li†o`†

» Grid Layout
Binary Tree I_icon_minitimeMon Aug 13, 2012 3:43 pm by †`Li†o`†

» Flow Layout
Binary Tree I_icon_minitimeMon Aug 13, 2012 3:41 pm by †`Li†o`†

» Border Layout
Binary Tree I_icon_minitimeMon Aug 13, 2012 3:38 pm by †`Li†o`†

» InputStreamAndOutputStream
Binary Tree I_icon_minitimeMon Aug 13, 2012 3:31 pm by †`Li†o`†

» Triangles Task 1 & 2
Binary Tree I_icon_minitimeMon Jul 23, 2012 3:32 pm by †`Li†o`†

» Java Central and Sub Class
Binary Tree I_icon_minitimeMon Jul 09, 2012 3:40 pm by †`Li†o`†

» Payroll Code Part 2
Binary Tree I_icon_minitimeMon Jul 02, 2012 4:03 pm by †`Li†o`†

» pakyu to .i.
Binary Tree I_icon_minitimeMon Jun 25, 2012 4:20 pm by `jhajha lanqs`

» Payroll Code
Binary Tree I_icon_minitimeMon Jun 25, 2012 3:58 pm by †`Li†o`†

» this is it ! xDD !!
Binary Tree I_icon_minitimeTue Feb 28, 2012 8:11 am by `jhajha lanqs`

» Summary/ Plot Of DATE MOVIE!!
Binary Tree I_icon_minitimeTue Feb 28, 2012 8:06 am by †`Li†o`†

» about valentines day !
Binary Tree I_icon_minitimeFri Feb 17, 2012 7:24 am by `jhajha lanqs`

» cos3 Number Guessing Game !
Binary Tree I_icon_minitimeMon Feb 13, 2012 7:49 am by @†`JeRoLD`†

» eto yown e....
Binary Tree I_icon_minitimeMon Feb 13, 2012 6:22 am by †`Li†o`†

Top posters
†`Li†o`† (80)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
`jhajha lanqs` (42)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
Jasper ! (12)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
@†`JeRoLD`† (9)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
hEEcHuL05 (9)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
†.frAnCis.† (6)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
jenny (5)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
†Yaphe†S† (3)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
Lhuisi†0 (1)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
julie cko (1)
Binary Tree I_vote_lcapBinary Tree I_voting_barBinary Tree I_vote_rcap 
May 2024
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  
CalendarCalendar

 

 Binary Tree

Go down 
AuthorMessage
`jhajha lanqs`

`jhajha lanqs`


Female Cancer Posts : 42
Points : 84
Reputation : 0
Birthday : 1995-07-02
Join date : 2011-09-26
Age : 28
Location : mangumit canlubang calamba city laguna
Job/hobbies : texting , playing DOTA

Binary Tree Empty
PostSubject: Binary Tree   Binary Tree I_icon_minitimeMon Jan 30, 2012 7:52 am

Quote :
class BinaryTreeExample {

public static void main(String[] args)

{
new BinaryTreeExample().run();
}

static class Node

{

Node left;
Node right;
int value;

public Node(int value) {
this.value = value;
}
}

public void run() {
Node rootnode = new Node(25);
System.out.println("Building tree with rootvalue " + rootnode.value);
System.out.println("=================================");
insert(rootnode, 11);
insert(rootnode, 15);
insert(rootnode, 16);
insert(rootnode, 23);
insert(rootnode, 79);
System.out.println("Traversing tree in order");
System.out.println("=================================");
printInOrder(rootnode);

}

public void insert(Node node, int value) {
if (value < node.value) {
if (node.left != null) {
insert(node.left, value);
} else {
System.out.println(" Inserted " + value +
" to left of node " + node.value);
node.left = new Node(value);
}
} else if (value > node.value) {
if (node.right != null) {
insert(node.right, value);
} else {
System.out.println(" Inserted " + value + " to right of node " + node.value);
node.right = new Node(value);
}
}
}

public void printInOrder(Node node) {
if (node != null) {
printInOrder(node.left);
System.out.println(" Traversed " + node.value);
printInOrder(node.right);
}
}
}
Back to top Go down
 
Binary Tree
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
†Asian Ins†i†u†e Of Compu†er Studies† :: †AE1DA†Computer†Programming†Section† :: †JAVA†-
Jump to: