Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 50
- void qinsert();
- void qremove();
- void display();
- int queue[MAX];
- int rear = - 1;
- int front = - 1;
- main()
- {
- char choice;
- while (1)
- {
- printf("U.Insert element to queue \n");
- printf("O.Eemove element from queue \n");
- printf("D.Display all elements of queue \n");
- printf("E.Quit \n");
- printf("Enter your choice : ");
- scanf(" %c", &choice);
- switch (choice)
- {
- case 'U':
- qinsert();
- break;
- case 'O':
- qremove();
- break;
- case 'D':
- display();
- break;
- case 'E':
- exit(1);
- default:
- printf("Wrong character! \n");
- } /* End of switch */
- } /* End of while */
- } /* End of main() */
- void qinsert()
- {
- int add;
- if (rear == MAX - 1)
- printf("Queue Overflow \n");
- else
- {
- if (front == - 1)
- /*If queue is initially empty */
- front = 0;
- printf("Inset the element in queue : ");
- scanf("%d", &add);
- rear = rear + 1;
- queue[rear] = add;
- }
- } /* End of qinsert() */
- void qremove()
- {
- if (front == - 1 || front > rear)
- {
- printf("Queue Underflow \n");
- return ;
- }
- else
- {
- printf("Element qremoved from queue is : %d\n", queue[front]);
- front = front + 1;
- }
- } /* End of qremove() */
- void display()
- {
- int i;
- if (front == - 1)
- printf("Queue is empty \n");
- else
- {
- printf("Queue is : \n");
- for (i = front; i <= rear; i++)
- printf("%d ", queue[i]);
- printf("\n");
- }
- } /* End of display() */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement