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_009.md

algo_009.md (582B)


      1 # algo_009
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to insert a node after a special key value.
      6 
      7 ## Algorithm
      8 ```
      9 procedure insertAfterKey(head, key)
     10 begin
     11     current ← head;
     12     while(current ≠ NULL && info(current) ≠ key)
     13         current ← next(current);
     14     endwhile
     15     if(current ≠ NULL)
     16         write("Enter the value: ");
     17         read(val);
     18         newNode ← getnode();
     19         info(newNode) ← val;
     20         next(newNode) ← next(current);
     21         next(current) ← newNode;
     22     else
     23         write("Key not found in the list.");
     24     endif
     25 end procedure
     26 ```