My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to show inserting and deleting from a queue

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
 clrscr();
 int a[20],front,rare,item,m;
 char c,y,n,str[2];
 cout<<"enter the number of elements(max 20): ";
 cin>>m;
 cout<<"enter the elements"<<endl;
 for(int i=0;i<m;i++)
 cin>>a[i];
 cout<<"enter the element to be inserted: ";
 cin>>item;
 front=0;
 rare=m-1;
 if(front==0&&rare==19)
 { cout<<"over flow";
   exit; }
 else
 { if(rare==19)
   rare=0;
   else
   rare=rare+1;
  }
  a[rare]=item;
  cout<<"queue after insertion the element is"<<endl;
  for(i=front;i<=rare;i++)
  cout<<a[i]<<endl;
  cout<<endl;
  cout<<"Are you want to delete an item"<<endl<<endl;
  cout<<"         if you want to delete one element than press y"<<endl;
  cout<<"         if you want to exit than press n"<<endl<<endl<<endl;
  cout<<"                                      Press yes\\no(y\\n)";
  cin>>c;
  if(c==110)
  exit;
  if(c==121)
  { if(front==0&&rare==-1)
    cout<<"queue is already empty";
    else
    front=front+1;
    cout<<"queue after deletion the element is"<<endl;
    for(int i=front;i<=rare;i++)
    cout<<a[i]<<endl;
    getch();
   }
   }

0 comments: