Robert W
Robert W

Reputation: 27

Recursively printing data in linked list nodes, but with multiple forward links C++ (Pic Included)

https://i.sstatic.net/3T1rj.jpg

So I know how to recursively print a tree with 1 l and 1 right ptr, but im stumped how to recursively print every possible node in this type of tree.

Im using this structure to keep track of different hash tables for a compiler.

Upvotes: 0

Views: 220

Answers (1)

David Schwartz
David Schwartz

Reputation: 182883

To print a node and everyone below it:

  1. Print this node.

  2. Loop through every link down from this node. For each linked node, print that node and every node below it (using this algorithm).

  3. Stop.

To print every node in the tree, perform this operation on the top node.

Note that a recursive algorithm is not advisable if the structure is deep. You should use an iterative one instead.

Upvotes: 5

Related Questions