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