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


Top 5 Contributors of the Month
G N
Akhil Raj
Dhananjay Kumar
laptop charles
Majith

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

 Subscribe to Code Snippets

Deletion in array queue

Posted By :Nikhil Kumar      Posted Date :28/02/2010   Points :10   Category: Collections    URL: http://fast-get.com

Deletion in array queue in c programming...
 


////DELETION IN ARRAY QUEUE////
 
#include<iostream.h>
#include<conio.h>
#include<process.h>
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<rear;i++)
cout<<q[i]<<"<-\t";
cout<<q[rear]<<endl;
}
 
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


Featured Articles


Design Pattern Interview Questions Part (3)
Software Architecture Interview Questions Part 3 State Pattern, Stratergy pattern,Visitor pattern, Adapter and fly weight ... Read More
Software Architecture Interview Questions Part 4- Design Patterns
(A) Can you explain bridge pattern? (A) Can you explain composite pattern? (I) Can you explain decorator pattern ? (A) Can you explain Façade pattern? (A) Can you explain chain of responsibility ( COR)? (I) Can you explain proxy pattern? (B) Can you explain template pattern? ... Read More
UML Interview Question Part 1
(B) Define UML? (I) Can you explain use case diagrams? (I) Can you explain primary and secondary actors? (I) How does a simple use case look like? (I) Can you explain 'Extend' and 'Include' in use cases? (I) Can you explain class diagrams? (B) How do we represent private, public and protected in class diagrams? (I) what does associations in a class diagram mean? (I) Can you explain aggregation and composition in class diagrams? (A) What are composite structure diagram and reflexive association in class diagrams? ... Read More
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