Traverse tree without recursion and stack in C

后端 未结 5 1225
日久生厌
日久生厌 2021-02-05 21:38

How to traverse each node of a tree efficiently without recursion in C (no C++)?

Suppose I have the following node structure of that tree:

struct Node
{
         


        
5条回答
  •  不思量自难忘°
    2021-02-05 22:10

    You'd have to store it in an iterable list. a basic list with indexes will work. Then you just go from 0 to end looking at the data.

    If you want to avoid recursion you need to hold onto a reference of each object within the tree.

提交回复
热议问题