bsc

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

algo_023.md (808B)


      1 # algo_023
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to insert a node after the specified node in double linked list.
      6 
      7 ## Algorithm
      8 ```
      9 procedure insert(dl, val, key)
     10 begin
     11     ptr ← dl;
     12     found ← 0;
     13     while(ptr)
     14         if(info(ptr) = key)
     15             found ← 1;
     16             break;
     17         endif
     18         ptr ← next(ptr);
     19     end while
     20     if(found)
     21         nptr ← getNode();
     22         info(nptr) ← val;
     23         next(nptr) ← NULL;
     24         prev(nptr) ← NULL;
     25         if(next(ptr) = NULL)
     26             prev(nptr) ← ptr;
     27             next(ptr) ← nptr;
     28         else
     29             next(nptr) ← next(ptr);
     30             prev(next(ptr)) ← nptr;
     31             next(ptr) ← nptr;
     32             prev(nptr) ← ptr;
     33         end if
     34     else
     35         write("key not found");
     36     endif
     37 end procedure
     38 ```
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror