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

algo_021.md (427B)


      1 # algo_021
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to insert a node at the beginning of a double linked list.
      6 
      7 ## Algorithm
      8 ```
      9 procedure insert_begin(dl, val)
     10 begin
     11     ptr ← getNode();
     12     info(ptr) ← val;
     13     prev(ptr) ← NULL;
     14     next(ptr) ← NULL;
     15     if(dl = NULL)
     16         dl ← ptr;
     17     else
     18         next(ptr) ← dl;
     19         prev(dl) ← ptr;
     20         dl ← ptr;
     21     endif
     22     return(dl);
     23 end procedure
     24 ```