Skip to content

Instantly share code, notes, and snippets.

@mostafa6765
Last active September 29, 2019 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafa6765/81d5bbb51ef4dfb8738ee13b80920e7d to your computer and use it in GitHub Desktop.
Save mostafa6765/81d5bbb51ef4dfb8738ee13b80920e7d to your computer and use it in GitHub Desktop.
push ,pop ,display with array c++ cpp
/******************************************************
QUEUE C++
AUTHOR URI:https://mostafa.itnishi.com
******************************************************/
#include<iostream>
#include<conio.h>
using namespace std;
int top=-1, z[5];
void push(int value)
{
if(top==4)
{
cout<<"\n Stack is Full or overflow!\n";
}
else
{
top++;
z[top]=value;
}
}
void pop()
{
if(top==-1)
{
cout<<"n stack is Empty or underflow!\n";
}
else
{
top--;
}
}
void display()
{
if(top==-1)
{
cout<<"\n nothing to display !\n";
}
else
{
cout<< "\n array is : \n";
for(int i=0;i<=top;i++)
{
cout<<"\t"<<z[i];
}
}
}
int main()
{
int value, choice;
do{
cout<<"\n 1.push \n 2.pop \n 3.display \n 4.exit\n \n input choice: ";
cin>>choice;
if(choice==1)
{
cout<<"\n enter a value";
cin>> value;
push(value);
}
if(choice==2)
{
pop();
}
if(choice==3)
{
display();
}
}
while(choice!=4);
cout<<"\n\n\n Existing......\n";
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment