Sunday, August 25, 2013

IMPLEMENT DQUEUE USING STL.


/****************************************************
      NAME      :-  JABIR DAUD PATHAN
      PROGRAM   :-  IMPLEMENT DQUEUE USING STL.
*****************************************************/

#include<iostream>
#include<deque>

using namespace std;

/*-------------<<  Main Function Starts  >>------------*/

int main()
 {
   deque <int> d;
   deque <int>::iterator i;
   int x,ch;
   char ans;

   do
    {
     cout<<"\n\n\t\t\t-------<< MENU >>-------";
     cout<<"\n\t\t\t1.Push Element at Front";
     cout<<"\n\t\t\t2.Push Element at Rear";
     cout<<"\n\t\t\t3.Pop Element from Front";
     cout<<"\n\t\t\t4.Pop Element from Rear";
     cout<<"\n\t\t\t5.Exit";
     cout<<"\n\t\t\t------------------------";
     cout<<"\n\nEnter your choice : ";
     cin>>ch;
     switch(ch)
             {
              case 1 :
                             cout<<"\nEnter The Element : ";
                             cin>>x;
                             d.push_front(x);
                             cout<<"The elements of the dequeue are : ";
                             for(i=d.begin() ; i!=d.end() ; i++)
                              {
                                cout<<*i<<" ";
                              }
                             break;

              case 2 :
                             cout<<"\nEnter The Element : ";
                             cin>>x;
                             d.push_back(x);
                             cout<<"The elements of the dequeue are : ";
                             for(i=d.begin() ; i!=d.end() ; i++)
                              {
                                cout<<*i<<" ";
                              }
                             break;

              case 3 :
                             cout<<"\n\nElement is poped from front is : "<<d.front();
                             d.pop_front();
                             cout<<"The elements of the dequeue are : ";
                             for(i=d.begin() ; i!=d.end() ; i++)
                              {
                                cout<<*i<<" ";
                              }
                             break;

              case 4 :
                             cout<<"\n\nElement is poped from rear is : "<<d.back();
                             d.pop_back();
                             cout<<"The elements of the dequeue are : ";
                             for(i=d.begin() ; i!=d.end() ; i++)
                              {
                                cout<<*i<<" ";
                              }
                             break;


              case 5 :
                             return 0;
                             break;
       }
      cout<<"\n\nDo you want to continue(Y/N) : ";
      cin>>ans;
    }while(ans=='y'||ans=='Y');
     return 0;
  }
/*-------------<<  End Of Main Function  >>---------------*/





/*-----------------<< OUTPUT SCREEN  >>-------------------*/

                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 1

Enter The Element : 1


The elements of the dequeue are : 1

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 2

Enter The Element : 2


The elements of the dequeue are : 1 2

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 1

Enter The Element : 3


The elements of the dequeue are : 3 1 2

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 2

Enter The Element : 4


The elements of the dequeue are : 3 1 2 4

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 3


Element is poped from front is : 3

The elements of the dequeue are : 1 2 4

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 4


Element is poped from rear is : 4

The elements of the dequeue are : 1 2

Do you want to continue(Y/N) : y


                                    -------<< MENU >>-------
                                    1.Push Element at Front
                                    2.Push Element at Rear
                                    3.Pop Element from Front
                                    4.Pop Element from Rear
                                    5.Exit
                                    ------------------------

Enter your choice : 5

/*********************************************************/

No comments:

Post a Comment