• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#include <stdlib.h>
2#include <stdio.h>
3#include "bin-trees.h"
4
5static void
6real_pre_order_traverse_no_recurse (tree_ptr root)
7{
8  struct stack_struct *stack = NULL;
9
10  if (root != NULL)
11    push (&stack, root);
12
13  while (stack != NULL)
14  {
15    tree_ptr current = pop (&stack);
16    printf ("%d ", current->data);
17    if (current->right != NULL)
18      push (&stack, current->right);
19    if (current->left != NULL)
20      push (&stack, current->left);
21  }
22  return;
23}
24
25void
26pre_order_traverse_no_recurse (tree_ptr root)
27{
28  printf ("pre-order traversal, without recursion: \n");
29  real_pre_order_traverse_no_recurse (root);
30  printf ("\n");
31}
32