Last active
November 4, 2017 14:58
-
-
Save mirsahib/40a7858043bc53f605241ebee1a5ba48 to your computer and use it in GitHub Desktop.
Assignment_5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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