.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

INSERTION IN ARRAY QUEUE

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

INSERTION IN ARRAY QUEUE in c Programming...
 

////INSERTION  IN ARRAY QUEUE////
 
#include
#include
#include
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;
}
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;
}
void display(int q[],int front,int rear)
{
if (front==-1)return;
for(int i=front;i
cout<
cout<
}
 
OUTPUT
 
ENTER ITEM FOR INSERTION:212
NOW THE QUEUE IS:212
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:234
NOW THE QUEUE IS:212<-  234
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:12
NOW THE QUEUE IS:212<-  234<-   12
WANT TO INSERT MORE ELEMENTS:y
 
ENTER ITEM FOR INSERTION:54
NOW THE QUEUE IS:212<-  234<-   12<-    54
WANT TO INSERT MORE ELEMENTS: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