/* implemaintaction Of Circular Queue */ #include<stdio.h> #define N 5 int queue[N]; int front=-1,rear=-1; //Function Declaractions void Enqueue(); void Dequeue(); void Peek(); void Display(); //Driver Program int main(){ int choice; do{ printf("\n***Circular Queue***\n"); printf("1. Enqueue\n"); printf("2. Dequeue\n"); printf("3. Peek\n"); printf("4. Display\n"); printf("0 To Exit\n"); printf("Enter Choice "); scanf("%d",&choice); switch(choice){ case 1: Enqueue(); break; case 2: Dequeue(); break; case 3: Peek(); break; case 4: Display(); break; default: printf("\n!Wrong Choice!\n"); } }while(choice!=0); return 0; } void Enqueue(){ int x; if(front==-1 && rear==-1){ printf("\nEnter X "); scanf("%d",&x); front=rear=0; queue[rear]=x; } else if((rear+1)%N==front){ printf("\nQueue Is Full\n"); } else{ printf("\nEnter X "); scanf("%d",&x); rear=(rear+1)%N; queue[rear]=x; } } void Dequeue(){ if(front==-1 && rear==-1){ printf("\nQueue Is Empty\n"); } else if(front==rear){ front=rear=-1; } else{ printf("%d",queue[front]); front=(front+1)%N; } } void Peek(){ if(front==-1 && rear==-1){ printf("\nQueue Is Empty\n"); } else{ printf("%d ",queue[front]); } } void Display(){ int i=front; if(front==-1 && rear==-1){ printf("\nQueue Is Empty\n"); } else{ while(i!=rear){ printf("%d ",queue[i]); i=(i+1)%N; } printf("%d",queue[i]); } }OUTPUT
Java
Tech News
Ad
implementation of Circular queue using Array
implementation of Circular queue using Array
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment