Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Last active November 4, 2017 14:58
Show Gist options
  • Save mirsahib/40a7858043bc53f605241ebee1a5ba48 to your computer and use it in GitHub Desktop.
Save mirsahib/40a7858043bc53f605241ebee1a5ba48 to your computer and use it in GitHub Desktop.
Assignment_5
#include <iostream>
using namespace std;
class Stack{
private:
int top;
int num_array [100];
public:
Stack(){
top = -1;
}
void push(int element){
top++;
num_array[top] = element;
}
void pop(){
if(top==-1){
cout<<"\nStack is empty"<<endl;
}else{
top--;
}
}
void display(){
for(int i=0;i<=top;i++){
cout<<num_array[i]<<" ";
}
}
};
int main()
{
Stack myStack;
myStack.push(1);
myStack.push(2);
myStack.push(3);
myStack.push(4);
myStack.push(5);
myStack.display();
myStack.pop();
cout<<endl;
myStack.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment