# Array Implementation Tree

• 02-18-2010, 11:38 AM
rsjava24
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 In-order. Can somebody show that example? Thank you.:)
• 02-18-2010, 11:43 AM
r035198x
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.
• 02-18-2010, 11:59 AM
rsjava24
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.
*/
• 02-18-2010, 12:23 PM
r035198x
1.) Please use code tags when posting code.
2.) Understand your algorithms and write them down.
3.) Then post your code with expected output vs what you actually got. Careful to post the code that you ran .e.g if (arr[nodePointer == 0) { couldn't possibly have even compiled.