Thursday, August 27, 2009

Queue Operation



#include<stdio.h>



#include<conio.h>




int

qu[100]={0};




int

ch,item,i,n,top=1;



main()



{



top=1;



ch=1;



clrscr();



printf("\nQUEUE
OPERATION"
);



printf("\n~~~~~~~~~~~~~~~");



printf("\nEnter
the size of queue:"
);



scanf("%d",&n);



printf("\n\n");



do



{



printf("\n1.push");



printf("\n2.pop");



printf("\n3.display");



printf("\n4.exit");



printf("\nEnter
your choice:"
);



scanf("%d",&ch);



switch(ch)



{




case
1:




{



push();




break
;




}



case
2:




{



pop();




break
;




}



case
3:




{



display();




break
;




}



}



}



while(ch<=3);



getch();



}



push()



{



if(top==n+1)



printf("\n
Queue is full"
);



else



{



printf("\nEnter
the value:"
);



scanf("%d",&qu[top]);



top+=1;



}



}



pop()



{



if(top==0)



printf("\nQueue
is empty"
);



else



{



item=qu[1];



top-=1;



n=n-1;



for(i=1;i<=top;i++)



qu[i]=qu[i+1];



printf("\n\nDeleted
item is=%d"
,item);



}



}



display()



{



if(top==0)



printf("\n\nQueue
is empty"
);



else



{



printf("\n\nThe
Queue values are"
);



for(i=1;i<top;i++)



{



printf("\n
%d"
,qu[i]);



}



}



}





No comments:

Post a Comment