• 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  }
20  return;
21}
22
23void
24pre_order_traverse_no_recurse (tree_ptr root)
25{
26  printf ("pre-order traversal, without recursion: \n");
27  real_pre_order_traverse_no_recurse (root);
28  printf ("\n");
29}
30