Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C - Possible to create a tree level by level?

Name: Anonymous 2010-05-25 12:39

I'm studying trees right now, and I'd like to find some examples of how to create a binary(or k-ary) tree one level at a time, since I can't find it anywhere and my brain isn't working.

Anyone have any input on this? C's lack of functions doesn't help either. Thanks ahead, /prog/

Name: Anonymous 2010-05-25 13:12

http://webdocs.cs.ualberta.ca/~holte/T26/tree-as-array.html

Create an array long enough to store all the nodes ( 2*(2^depth)-1 or something )

Store first level (the root element) at the 1.st index position.
Store second level at 2 to 3.
Store third level at 4 to 7.
Store fourth level at 8 to 15.
etc.

Traversing the tree in this implementation:
root node index 1
left child index 2*n
right child index 2*n+1

>>``C's lack of functions''
wait what

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List