From 13df90798ca73f09269cdd7c6f75a6b00fd80efb Mon Sep 17 00:00:00 2001 From: ank2710 <56040254+ank2710@users.noreply.github.com> Date: Wed, 2 Oct 2019 10:57:51 +0530 Subject: [PATCH] Created Stack (Array). Implemented Stack Using Array. --- Stack(Array).cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Stack(Array).cpp diff --git a/Stack(Array).cpp b/Stack(Array).cpp new file mode 100644 index 0000000..19e8477 --- /dev/null +++ b/Stack(Array).cpp @@ -0,0 +1,47 @@ +#include + +int main(){ + int a[50]; + int c=0; + int top=-1,data; + + while(c<3){ + cout<<"1.Push\n2.Pop\n3.Exit\n"; + cin>>c; + + switch(c){ + case 1: + top++; + if(top>49){ + top--; + cout<<"Overflow\n"; + } + else{ + cout<<"Enter Data\n"; + cin>>a[top]; + cout<<"Item Inserted\n"; + } + break; + + case 2: + if(top==-1){ + cout<<"Underflow\n"; + } + else{ + top--; + } + break; + + } + + if(top!=-1){ + cout<<"Stack:\n"; + for(int i=top;i>=0;i--){ + cout<<"<-"<