{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2c03-review - 00052 - well We use the ADT queue here to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
8 end return(L); end 5.[15] The level-order listing of the nodes of a tree first lists the root, then all nodes of depth a, then all nodes of depth 2, and so on. Nodes at the same depth are listed in left-to-right order. Write a program to list the nodes of a tree in level-order. Assume you have all appropriate ADT TREE operations (like PARENT, LEFTMOST-CHILD, RIGHT-SIBLING, ROOT, etc.) implemented. In your solution you may assume having some appropriate list operations implemented as
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: well. We use the ADT queue here to make the code simple. procedure level-order(T) var level: QUEUE of nodes; v: node; begin v:= ROOT(T); MAKENULL_QUEUE(level); ENQUEUE(v, level); while not empty(level) do begin v:=FRONT(level); DEQUEUE(level); P R I N T v ; if LEFTMOST_CHILD(v,T)<> null then begin v:= LEFTMOST_CHILD(v,T); ENQUEUE(v,level); while RIGHT_SIBLING(v,T)<>null do begin v:=RIGHT_SIBLING(v,T); ENQUEUE(v,level); e n d e n d end end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online