.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Deletion in array queue

Posted By:Nikhil Kumar       Posted Date: February 28, 2010    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  

Deletion in array queue in c programming...
 

////DELETION IN ARRAY QUEUE////
 
#include
#include
#include
int remove(int[]);
int insert(int[],int);
void display(int[],int,int);
const int size=50;
int q[size],front= -1,rear= -1;
void main()
{
int item,res;
char ch='y';
while(ch=='y')
{
cout<<"\nENTER ITEM FOR INSERTION:";
cin>>item;
res=insert(q,item);
cout<<"NOW THE QUEUE IS:";
display(q,front,rear);
cout<<"WANT TO INSERT MORE ELEMENTS:";
cin>>ch;
}
ch='y';
while(ch=='y')
{res=remove(q);
cout<<"ELEMENT DELETED";
cout<<"NEW QUEUE IS:";
display(q,front,rear);
 
cout<<"want to delete more:";
cin>>ch;
}
}
int insert(int q[],int ele)
{
if(rear==size-1)return -1;
else if(rear==-1)
{
front=rear=0;
q[rear]=ele;
}
else{
rear++  ;
q[rear]=ele;
}return 0;
}
int remove(int q[])
{
int ret;
if (front==-1)return -1;
else{ret=q[front];
if(front==rear)front=rear=-1;
else front++;
}
return ret;
}
void display(int q[],int front,int rear)
{
if (front==-1)return;
for(int i=front;i
cout<
cout<
}
 
OUTPUT
 
***deletion in array queue***
 
ENTER ITEM FOR INSERTION:23
NOW THE QUEUE IS:23
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:12
NOW THE QUEUE IS:23<-   12
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:45
NOW THE QUEUE IS:23<-   12<-    45
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:33
NOW THE QUEUE IS:23<-   12<-    45<-    33
WANT TO INSERT MORE ELEMENTS:n
ELEMENT DELETEDNEW QUEUE IS:12<-        45<-    33
want to delete more:n


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend