Results 1 to 4 of 4
Thread: Array Implementation Tree
 02182010, 10:38 AM #1Member
 Join Date
 Jan 2010
 Posts
 23
 Rep Power
 0
Array Implementation Tree
Hello everybody! Can somebody show me an example of an array implementation tree? For example I haVe 16 indices. 0000000000000000. I input 10,9,12,24,25, and output is : 10,9,12,000000240002600. The first index is what I've first input and second is 9 which is less than 10 and obviously it is put at the left of 10. And so on. Then an example of Inorder. Can somebody show that example? Thank you.:)
 02182010, 10:43 AM #2Senior Member
 Join Date
 Aug 2009
 Posts
 2,388
 Rep Power
 14
Are you asking for code? Don't do that if you are supposed to be learning. Write your own and ask for help if you are stuck with your code.
 02182010, 10:59 AM #3Member
 Join Date
 Jan 2010
 Posts
 23
 Rep Power
 0
Array Implementation Tree
Ok here's my code:
Assuming i have a class name and import java.io*;
int arr [] new arr[16];
int nodePointer = 0;
System.out.println("Enter size");
int a = Integer.parseInt(br.readLine());
for (int i =0; i < a; i++) {
System.out.println("Enter element"+(i+1)+" ");
int x = Integer.parseInt(br.readLine());
if (arr[nodePointer == 0) {
arr[nodePointer] = x;
nodePointer = 0;
else if(x < arr[nodePointer]) {
nodePointer = nodePointer *2 +1;
}
else if (x > arr[nodePointer]) {
nodePointer = nodePointer *2 +2;
}
}
for (int i =0; i < a; i++) {
System.out.println(arr[i]);
}
/*
my output is: for example i entered 5 elements 10,9,12,24,26 and it shown only 3 elements like 10, 24, and 26...the 9 and 12 is missing...can somebody help me? Thank you.
*/
 02182010, 11:23 AM #4Senior Member
 Join Date
 Aug 2009
 Posts
 2,388
 Rep Power
 14
Similar Threads

Binary Search Tree implementation
By Ceasar in forum Advanced JavaReplies: 5Last Post: 10132009, 03:43 PM 
arraybased implementation question
By intelli in forum New To JavaReplies: 1Last Post: 04182009, 05:18 PM 
How to create tree view of the given JList implementation
By aneesahamedaa in forum AWT / SwingReplies: 3Last Post: 10062008, 02:45 PM 
Binary Tree Implementation in Java
By Java Tip in forum java.langReplies: 0Last Post: 04162008, 10:35 PM
Bookmarks