Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define size 50
- int front = -1, rear = -1;
- int queue[size];
- void enqueue(){
- int item;
- if(rear == size - 1){
- printf("\nOverflow");
- }
- else {
- printf("Enter element to be inserted: ");
- scanf("%d", &item);
- if(front == -1 && rear == -1){
- front = 0;
- }
- queue[++rear] = item;
- }
- }
- void dequeue(){
- int item = queue[front];
- if(front == -1){
- printf("\nUnderflow");
- }
- else {
- printf("\n%d removed from queue\n", item);
- if(front == rear) {
- rear = -1;
- front = -1;
- }
- else {
- front++;
- }
- }
- }
- void display() {
- if (front == -1 && rear == -1) {
- printf("\nQueue Underflow\n");
- } else {
- int i;
- printf("\n{");
- for (i = front; i <= rear; i++) {
- printf("%d, ", queue[i]);
- }
- printf("}\n");
- }
- }
- int main() {
- int arg;
- while (1) {
- printf("\n******************");
- printf("\nEnter your choice:\n1. Enqueue\n2. Dequeue\n3. Display\n0. Exit");
- printf("\n******************\n");
- scanf("%d", &arg);
- switch (arg) {
- case 1: {
- enqueue();
- break;
- }
- case 2: {
- dequeue();
- break;
- }
- case 3: {
- display();
- break;
- }
- case 0: {
- exit(0);
- }
- default: {
- printf("\nInvalid Argument\n");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement