From 2a689fed7166f6bd95f3ca3de99a0a35cd4e6611 Mon Sep 17 00:00:00 2001 From: Aman Kumar Dewangan Date: Sat, 26 Jun 2021 13:46:10 +0530 Subject: [PATCH] Add files via upload --- .../_05)_basics_of_array_imple_of_stack.cpp | 81 +++++++++++++++++++ .../C++/_06)_reverse_sentence_using_stack.cpp | 43 ++++++++++ .../09]. Stack/C++/_07)_reverse_stack.cpp | 59 ++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 1]. DSA/1]. Data Structures/09]. Stack/C++/_05)_basics_of_array_imple_of_stack.cpp create mode 100644 1]. DSA/1]. Data Structures/09]. Stack/C++/_06)_reverse_sentence_using_stack.cpp create mode 100644 1]. DSA/1]. Data Structures/09]. Stack/C++/_07)_reverse_stack.cpp diff --git a/1]. DSA/1]. Data Structures/09]. Stack/C++/_05)_basics_of_array_imple_of_stack.cpp b/1]. DSA/1]. Data Structures/09]. Stack/C++/_05)_basics_of_array_imple_of_stack.cpp new file mode 100644 index 000000000..b2f2200be --- /dev/null +++ b/1]. DSA/1]. Data Structures/09]. Stack/C++/_05)_basics_of_array_imple_of_stack.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class stack{ + int* arr; + int top; + + public: + stack(int n) + { + arr = new int[n]; + top= -1; + } + + void push(int x,int n) + { + if(top == n-1) + { + cout<<"\nStack Overflow"; + return; + } + + top++; + arr[top] = x; + } + + void pop() + { + if(top == -1) + { + return; + } + top--; + } + + int peek() + { + if(top == -1) + { + cout<<"\nNo element "; + return -1; + } + return arr[top]; + } + + bool empty() + { + return top==-1; + } +}; + + + +int main() + { + int n,x; + cin>>n; + stack st(n); + + + for(int i=0;i>x; + st.push(x,n); + } + + for(int i=n;i>=0;i--) + { + cout< +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void reversestring(string s) + { + stack st; + + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void insertatbottom (stack &st, int ele) + { + if(st.empty()) + { + st.push(ele); + return; + } + int topele = st.top(); + st.pop(); + insertatbottom(st,ele); + + st.push(topele); + } + +void reversestack(stack &st) + { + if(st.empty()) + { + return; + } + + int ele = st.top(); + st.pop(); + reversestack(st); + insertatbottom(st,ele); + } + +int main() + { + stack st; + int n,e; + cin>>n; + for(int i=0;i>e; + st.push(e); + } + + reversestack(st); + + while(!st.empty()) + { + cout<