I have completed a red black tree in c and i find it hard to print it in level-order. I have a print-inorder but i cant imagine how am i supposed to display it as a tree in the console print. Is it feasible? Can we implement BFS or DFS here? i’ve found an algorithm in wiki but i cant apply it.
If anyone has code for it in C could you post it here so i can study it?
from wiki:
levelorder(root)
q = empty queue
q.enqueue(root)
while not q.empty do
node := q.dequeue()
visit(node)
if node.left ≠ null
q.enqueue(node.left)
if node.right ≠ null
q.enqueue(node.right)
You can do a BFS, but it might be easier to do an iterative deepening search, since that will save you the trouble of implementing a FIFO queue in C. Pseudocode: