Advertisement
Rehan_Rahman26

Enqueue/Dequeue

Apr 4th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. int front,back;
  2.  
  3. front = back = -1;
  4.  
  5. void Enqueue(int n){
  6.     arr[++back] = n;
  7.  
  8.     if(front == -1)front++;
  9. }
  10.  
  11. int Dequeue(){
  12.     if(front == -1){
  13.         printf("Queue is empty");
  14.         return -1;
  15.     }
  16.  
  17.     int x = arr[front];
  18.     if(front == back){
  19.         front = back = -1;
  20.     }  
  21.  
  22.     front++;
  23.  
  24.     return x;
  25.    
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement