+ 1
Linked list to binary tree
Hi I have node class which takes care of int as data and next pointer. Now same is used as member of mylinkedlist class. Can we use the same class linkedlist as binary tree ? What my thought was to have new class as binarytree with two members, mylinkedlist and node*. Is it okay or not ?
4 Antworten
+ 1
To do a binary tree you just need head node, being a node (left) value (right).
Now, can you do a binary linked list with a linked list? Yes, but it's not the best way to implement it.
Quick pseudo-code of a binary tree:
Node {
Node left;
Node value;
Node right;
}
Tree {
Node head
}
+ 1
With a list would be:
Node {
int value;
List<Node> son;
}
Tree {
Node head;
}
This way you need to define the left son as index 0 and 1 as right son.
+ 1
Okay...thanks a lot
0
Thanks Tomás Ribeiro
Binary tree node is clear..
Could you plz elaborate on how to implement binary tree with list... i got that it is not best way but just curious to know how to do so