Advertisement
tonygms3

Untitled

Sep 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include<stdio.h>
  2. const int SIZE = 10;
  3. int qData[10];
  4. int front = 0,rear = -1;
  5. int qInsert(int number);
  6. int qDelete();
  7. void display();
  8.  
  9. int main(){
  10.     int option = 0,number;
  11.  
  12.     while(1){
  13.         printf("Enter 1 to insert, 2 to delete, 3 to display\n");
  14.         scanf("%d",&option);
  15.         if(option==1){
  16.             printf("Enter number to insert\n");
  17.             scanf("%d",&number);
  18.             printf("\n%d has been inserted\n",qInsert(number));
  19.         }else if(option == 2){
  20.             printf("%d has been removed from the queue\n",qDelete());
  21.         }else if(option == 3){
  22.             display();
  23.         }else if(option == 4){
  24.             break;
  25.         }
  26.     }
  27. return 0;
  28. }
  29. void display(){
  30.  
  31. }
  32. int qDelete(){
  33.     if(front == -1){
  34.         printf("Cannot Dequeue any more, Queue is empty\n");
  35.     }
  36.     else{
  37.         int temp = 0;
  38.         temp = qData[front];
  39.         front++;
  40.         return temp;
  41.     }
  42. }
  43. int qInsert(int number){
  44.     if(rear == SIZE){
  45.         printf("Cannot enqueue any more, Queue is Full\n");
  46.     }
  47.     else{
  48.         rear++;
  49.         qData[rear] = number;
  50.         return number;
  51.         }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement