P. 1
Lab 8

Lab 8

|Views: 6|Likes:
Published by Sandeep V Gowda

More info:

Published by: Sandeep V Gowda on Nov 12, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

11/12/2010

pdf

text

original

8.Write a C Program to simulate the working of a circular queue of integers using an array. Provide the following operations: a.

Insert b.Delete c.Display. PROGRAM #include<stdio.h> #include<conio.h> #include<process.h> #define size 5 int cqueue[size]; int front=0,rear=-1,count; void cinsert(int); int cdelete1(); void cdisplay(); void main() { int ele; int choice; clrscr(); while(1) { printf("enter choice 1.Insert 2.Delete 3.Display 4.Exit\n"); scanf("%d",&choice); switch(choice) { case 1:printf("Enter the element\n"); scanf("%d",&ele); cinsert(ele); break; case 2:ele=cdelete(); if(ele==-999) { printf("Queue empty\n"); } else { printf("The element deleted is %d\n",ele); } break; case 3:cdisplay(); break; case 4:exit(0); default:printf("Invalid choice\n"); break; } } } void cinsert(int ele) { if(count==size) { printf("Queue full\n"); }

else { count=count+1; rear=(rear+1)%size; cqueue[rear]=ele; } } int cdelete() { int temp; if(count==0) { temp=-999; } else { count=count-1; temp=cqueue[front]; front=(front+1)%size; } return(temp); } void cdisplay() { int i,j; j=front; for(i=0;i<count;i++) { printf("%d\t\n",cqueue[j]); j=(j+1)%size; } }

OUTPUT enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 10 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 20 enter choice 1.Insert 2.Delete 3.Display 4.Exit 3 10 20 enter choice 1.Insert 2.Delete 3.Display 4.Exit 2 The element deleted is 10 enter choice 1.Insert 2.Delete 3.Display 4.Exit

2 The element deleted is 20 enter choice 1.Insert 2.Delete 3.Display 4.Exit 2 Queue empty enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 11 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 22 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 33 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 44 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 55 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 66 Queue full enter choice 1.Insert 2.Delete 3.Display 4.Exit 2 The element deleted is 11 enter choice 1.Insert 2.Delete 3.Display 4.Exit 1 Enter the element 66 enter choice 1.Insert 2.Delete 3.Display 4.Exit 3 66 22 33 44 55 enter choice 1.Insert 2.Delete 3.Display 4.Exit 4

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->