Need help converting a complete binary tree from array to a dynamic

I have an array ["a","b","c","null","d","e",null] and I want to convert it to the Node style where each node is linked by node.left and node.right.

I don't have a problem implementing this structure by sorting it, but I do have a problem implementing it by inserting it level order.

Can anyone offer any suggestions.

[337 byte] By [javahockeya] at [2007-11-26 22:47:40]
# 1
A pre/in/postorder traversal of a binary tree is not enough to reconstructthe entire tree in a unique way. You either need another traversal orsome other information such as the level of a node.kind regards,Jos
JosAHa at 2007-7-10 12:06:45 > top of Java-index,Java Essentials,New To Java...
# 2

Not very OOP, and i'd definitely use one of the java collections for this, but nevertheless:

public class ArrayToLinkedList {

static String[] myarray = { "a", "b", "c", null, "d", "e", null };

static Node first;

static class Node {

Node prev;

Node next;

String data;

Node(Node prev, String s) {

if (prev == null)

first = this;

else prev.next = this;

next = null;

data = s;

}

};

public static void main(String[] args) {

Node prev = null;

for (String s : myarray)

prev = new Node(prev, s);

for (Node n = first; n != null; n = n.next)

System.out.println(n.data == null ? "null" : n.data);

}

}

deepravea at 2007-7-10 12:06:45 > top of Java-index,Java Essentials,New To Java...
# 3
Whoops, missed the binary tree reference, sorry.
deepravea at 2007-7-10 12:06:45 > top of Java-index,Java Essentials,New To Java...