diff --git a/CPP/data-structures/stack.cpp b/CPP/data-structures/stack.cpp new file mode 100644 index 0000000..2f82fd6 --- /dev/null +++ b/CPP/data-structures/stack.cpp @@ -0,0 +1,41 @@ +/*Stack Implementation using Arrays in C++ + created by DarkSun27*/ + +#include +#define size 100 +using namespace std; + +int arr[size],tos=0; +void push(int value) +{ + if(tos==size) + { + cout<<"Size of stack is full"; + return; + } + arr[tos++]=value; +} +int pop() +{ + if(tos!=0) + { + return arr[--tos]; + } + cout<<"Empty Stack"; + return -1; +} +int main(){ + int t; //defines number of times user wants to test stack + cin>>t; + for(int i=0;i>opt; // 1 for push and 2 for pop + switch(opt) + { + case 1:int value;cin>>value;push(value);break; + case 2:cout<