#include<stdio.h> #include<conio.h> #define size 5 int queue[size],rear=-1,front=-1,item; void insert(); void delet(); void display(); void main() { int choice; clrscr(); do { printf("\n1.Insert\n2.Delete\n3.Display\n4.Exit\nChoose one: "); scanf("%d",&choice); switch(choice) { case 1: insert(); break; case 2: delet(); break; case 3: display(); break; case 4: break; default: printf("Invalid choice.\n"); } } while(choice!=4); } void insert() { if((front==0 && rear==size-1) || front==rear+1) printf("Queue is full.\n"); else { printf("\nEnter the element: "); scanf("%d",&item); if(rear==-1) { rear=0; front=0; } else if(rear==size-1) rear=0; else rear++; queue[rear]=item; printf("Item inserted: %d\n",item); } } void delet() { if(front==-1) printf("Queue is empty.\n"); else { item=queue[front]; if(front==rear) { front=-1; rear=-1; } else if(front==size-1) front=0; else front++; printf("Element deleted: %d\n",item); } } void display() { int i; if(front==-1) printf("Queue is empty.\n"); else if(front>rear) { for(i=front;i<=size;i++) { printf("%d\t",queue[i]); } for(i=0;i<=rear;i++) { printf("%d\t",queue[i]); } } else { for(i=front;i<=rear;i++) { printf("%d\t",queue[i]); } } }
Search This Blog
Tuesday, 27 October 2015
Circular queue using array
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment