bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / algorithms / algo_046.md

algo_046.md (526B)


      1 # algo_046
      2 
      3 ### Problem Statement
      4 
      5 > Write a non-recursive algorithm for preorder traversal of a binary tree.
      6 
      7 ## Algorithm
      8 ```
      9 procedure preorder(T)
     10 begin
     11     ptr ← T;
     12     flag ← 1;
     13     while (flag = 1) do
     14         while (ptr ≠ NULL) do
     15             write(INFO(ptr));
     16             push(stack, ptr);
     17             ptr ← LC(ptr);
     18         endwhile
     19         if (!isEmpty(stack)) then
     20             ptr ← pop(stack);
     21             ptr ← RC(ptr);
     22         else
     23             flag ← 0;
     24         endif
     25     endwhile
     26 end procedure
     27 ```
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror