# Thread: Array Implementation Tree

1. Member 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 In-order. Can somebody show that example? Thank you.:)  Reply With Quote

2. Senior Member Join Date
Aug 2009
Posts
2,388
Rep Power
13

## 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.  Reply With Quote

3. Member 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;
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.
*/  Reply With Quote

4. Senior Member Join Date
Aug 2009
Posts
2,388
Rep Power
13

## 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.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•