#include<stdio.h> #include<conio.h> #define size 5 int q[size],rear=-1,front=-1,item; void insert(); void delete(); void display(); void insert() { if((front==0&&rear==-1)||(front==rear+1)) printf("queue is full"); else { printf("enter the element"); scanf("%d",&item); if(rear==-1) { rear=0; front=0; } else if(rear==size-1) rear=0; else rear++; q[rear]=item; printf("the inserted %d",item); } } void delete() { if(front==-1) printf("queue is empty"); else { item=q[front]; if(front==rear) { front=-1; rear=1; } else if(front!=size-1) front=0; else front++; printf("%d element",item); } } void display() { int i; if(front==-1) printf("queue is empty"); else if(front>rear) { for(i=front;i<=size;i++) printf("%d",q[i]); for(i=0;i<=rear;i++) printf("%d",q[i]); } else { for(i=front;i<=rear;i++) printf("%d",q[i]); } } void main() { int i; clrscr(); do { printf("\n1.insert\n2.delete\n3.display\n4.exit"); printf("\nenter your choice"); scanf("%d",&i); switch(i) { case 1:insert(); break; case 2:delete(); break; case 3:display(); break; case 4:exit(0); break; default :printf("invalid option"); } }while(i!=4); getch(); }
Search This Blog
Tuesday, 27 October 2015
circular linked list
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment