Custom Search
Showing posts with label insertion and deletion in queue. Show all posts
Showing posts with label insertion and deletion in queue. Show all posts

Saturday, 16 June 2012

Linear Queue using C++


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com


#include<stdio.h>
#include<conio.h>

#define max 3
class stack
 {
   int  item[max];
   int top;
  public:
     void push();
     void pop();
     void display();
     stack()
     {top=-1;}

   };
void stack::push()
  {
    int value;
     if(top==max-1)
       {
       cout<<"Stack is full insertion not possible\n";
}
      else
{
cout<<"\nEnter the value to be inserted\n";
cin>>value;
top=top+1;
item[top]=value;
}
   }
void stack::pop()
   {
    int value;
    if(top==-1)
     {
       cout<<"Stack empty\n ";
       }
    else
    {
      value=item[top];
      cout<<"deleted item is"<
      top=top-1;
      }
    }
 void stack::display()
   {
   if(top==-1)
     {
      cout<<"Stack is empty\n" ;
      }
   else
    {
     cout<<"Elements in stack are\n";
      for(int i=top;i>=0;i--)
{
cout<
}
       getch();
    }
     }
void main()
{
 int choice;
 char ch;
 stack s;
 clrscr();
 do
   {
     cout<<"MENU\n";
     cout<<"1.Insertion\n" ;
     cout<<"2.Deletion\n";
     cout<<"3.Display\n";
     cout<<"Enter your choice\n";
     cin>>choice;
     switch(choice)
      {
      case 1 :s.push();break;
      case 2 :s.pop();break;
      case 3 :s.display();break;
      default:cout<<"Invalid choice\n";

      }
     cout<<"\nDo you want to continue(yes=y,no=n)";
     cin>> ch;
    }while(ch=='Y'||ch=='y');
     getch();

   }

Read more

LinkWithin

Related Posts Plugin for WordPress, Blogger...