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

algo_038.md (503B)


      1 # algo_038
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to enqueue (circular queue)
      6 
      7 ## Algorithm
      8 ```
      9 Procedure enqueue(Q[], front, rear, Qsize, val)
     10 begin
     11     if ((rear + 1) % Qsize = front) then
     12         write("Queue full, insertion can't be done.");
     13     else
     14         if (front = -1) then
     15             front ← 0;
     16             rear ← 0;
     17         else
     18             rear ← (rear + 1) % Qsize;
     19         endif
     20 
     21         Q[rear] ← val;
     22         write("Inserted element: ", val);
     23     endif
     24 end procedure
     25 ```