Results 1 to 4 of 4
  1. #1
    rsjava24 is offline Member
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Default 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.:)

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  3. #3
    rsjava24 is offline Member
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Default 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.
    */

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

Similar Threads

  1. Binary Search Tree implementation
    By Ceasar in forum Advanced Java
    Replies: 5
    Last Post: 10-13-2009, 03:43 PM
  2. array-based implementation question
    By intelli in forum New To Java
    Replies: 1
    Last Post: 04-18-2009, 05:18 PM
  3. How to create tree view of the given JList implementation
    By aneesahamedaa in forum AWT / Swing
    Replies: 3
    Last Post: 10-06-2008, 02:45 PM
  4. Binary Tree Implementation in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:35 PM

Posting Permissions

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