diff --git a/Stack-DataStructure/ImplementationUsingArray.cpp b/Stack-DataStructure/ImplementationUsingArray.cpp new file mode 100644 index 00000000..e43b5063 --- /dev/null +++ b/Stack-DataStructure/ImplementationUsingArray.cpp @@ -0,0 +1,94 @@ +//Stack Implementation Using Array +#include +using namespace std; + +class Stack { + public: + int size; + int *arr; + int top; + + Stack(int size) + { + this->size=size; + arr= new int[size]; + top=-1; + } + + + void push(int element) + { + if(size-top>1) + { + top++; + arr[top]=element; + } + else + { + cout<<"Stack is overflow"<=0) + { + top--; + } + else + { + cout<<"Stack is Underflow."<=0) + { + return arr[top]; + } + else{ + cout<<"Stack is empty"<