bsc

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

algo_010.md (753B)


      1 # algo_010
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to insert an element at a perticular position.
      6 
      7 ## Algorithm
      8 ```
      9 procedure insertPosition(head, pos, val)
     10 begin
     11     newNode ← getNode();
     12     info(newNode) ← val;
     13     next(newNode) ← NULL;
     14     if(pos < 1) 
     15         write("Invalid Input.");
     16     else if(pos = 1)
     17         next(newNode) ← head;
     18         head ← newNode;
     19     else
     20         current ← head;
     21         for(i ← 1; i < pos && current ≠ NULL; i ← i + 1)
     22             current ← next(current);
     23         end for
     24         if(current = NULL)
     25             write("Invalid  Input.");
     26         else
     27             next(newNode) ← next(current);
     28             next(current) ← newNode;
     29         endif
     30     endif
     31     return(head);
     32 end procedure
     33 ```
© 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