In the Tree
abstraction, that is currently being written(as code practice),
/************ tree.h *********************/
.....
/****************** Usage-start ************/
#if defined(LCRS)
typedef struct LCRSTree Tree;
#elif defined(MULTI_WALK)
typedef struct multiWalkTree Tree;
#elif defined(BINARY_TREE)
typedef struct BinaryTree Tree;
#else
#error "Invalid representation\n"
#endif
.....
typedef void(*visitFunc)(void *);
Tree * newTree(void);
bool destroyTree(Tree *);
...
void preOrderTraversal(Tree*, visitFunc);
void postOrderTraversal(Tree *, visitFunc);
void breadthFirstTraversal(Tree *, visitFunc);
void inOrderTraversal(struct BinaryTree *, visitFunc);
.....
#endif /* TREE_H */
/**************** Usage-end ******************/
inOrderTraversal()
is declared as,
void inOrderTraversal(struct BinaryTree *, visitFunc);
which mean, inOrderTraversal
accept binary tree but not N-ary tree(N>2), unlike pre-, post-, breadth first traversals.
Idea is inspired from this answer, where it says: In-order traversal is a special case. It probably only makes sense for binary trees.
Question:
Before final code change, Please confirm my understanding on usage of inOrderTraversal()
in the above code.