Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackPat
//g++ 7.4.0 //Stack Pattern : Pattern making using Stack //Test driver code is created by Rezaul Hoque on February 08, 2021 // please contact at jewelmrh@yahoo.com #include <iostream> #include <string> using namespace std; template <class T> class Stack{ int max; int top; T* data; public: Stack (int s=100) : max(s),top(-1){ data= new T[max];} ~Stack(){ delete [] data;} bool push (const T&); T pop(); bool isEmpty(); bool isFull(); }; template <class T> bool Stack<T>::push(const T& x) { if(top>(max-1)) { cout <<" Sorry stack overflow!"; return false; } else { data[++top]=x; cout <<x<<endl; return true; } } template <class T> T Stack<T>::pop() { if(top<0) {cout <<"Sorry stack underflow!"; return 0; } else { T x = data[top--]; return x; } } template <class T> bool Stack<T>::isEmpty() { return (top<0); } template <class T> bool Stack<T>::isFull() { return (top=max-1); } int main() { Stack<char> star(81); for (int i=0;i<9;i++){ if (i%2==0) { star.push('>');star.push('>');star.push('>');star.push('>');star.push('>');star.push('>');star.push('>');star.push('>');star.push(' ');cout <<"\n"; } else { star.push(' ');star.push('<');star.push('<');star.push('<');star.push('<');star.push('<');star.push('<');star.push('<');star.push('<');cout<<"\n";} } cout<<" Now the pattern looks like:\n"; for(int i=0;i<9;i++) { if(i%2==0) { cout<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<"\n"; } else { cout<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<star.pop()<<"\n"; } } return 0; }
run
|
edit
|
history
|
help
0
thermal_containers
MergeSort
Continuous Sub Set with given sum
Triplet sum in array
TraceMarrix
cp.cpp
virtual function
namelookup
SEJM BLURWA
cppPyClamInher