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

Archives

program to insert an element in the 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<<"\nqueue 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(y\\n)";
  dhami:
  c=getch();
  if(c=='n')
  exit;
  if(c=='y')
  { if(front==0&&rare==-1)
    cout<<"\nqueue is already empty";
    else
    front=front+1;
    cout<<"\nqueue after deletion the element is"<<endl;
    for(int i=front;i<=rare;i++)
    cout<<a[i]<<endl;
    getch();
    exit;
   }

   }

0 comments: