bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / algorithms / algo_044.md

algo_044.md (520B)


      1 # algo_044
      2 
      3 ### Problem Statement
      4 
      5 > Write a non-recursive algorithm for inorder traversal of a binary tree.
      6 
      7 ## Algorithm
      8 ```
      9 procedure inorder(T)
     10 begin
     11     ptr ← T;
     12     flag ← 1;
     13     while (flag) do
     14         while (ptr ≠ NULL) do
     15             push(stack, ptr);
     16             ptr ← LC(ptr);
     17         endwhile
     18         if (!isEmpty(stack)) then
     19             ptr ← pop(stack);
     20             write(INFO(ptr));
     21             ptr ← RC(ptr);
     22         else
     23             flag ← 0;
     24         endif
     25     endwhile
     26 end procedure
     27 ```