Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackQuiz
//g++ 7.4.0 //Stack Quiz //credit internet, John R Hubbard, University of Richmond //an update is made into this code on February 8 , 2021 ----Rezaul Hoque #include <iostream> 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); } /****************************************************'* //Test driver on February 07, 2021 before update int main() { Stack<int> idStack(3); Stack<char> namStack(3); Stack<int> scoreStack(3); idStack.push(3); idStack.push(2); idStack.push(1); namStack.push('M'); namStack.push('L'); namStack.push('K'); scoreStack.push(10); scoreStack.push(15); scoreStack.push(20); cout<<" Id, name and quiz score:\n"; //These repeating actions could easily be done by for looping cout <<idStack.pop()<<"\t"<<namStack.pop()<<"\t"<<scoreStack.pop()<<endl; cout <<idStack.pop()<<"\t"<<namStack.pop()<<"\t"<<scoreStack.pop()<<endl; cout <<idStack.pop()<<"\t"<<namStack.pop()<<"\t"<<scoreStack.pop()<<endl; return 0; } *****************************************************/ //Test driver after the update int main() { Stack<int> idStack(3); Stack<char> namStack(9); Stack<int> scoreStack(3); idStack.push(3); idStack.push(2); idStack.push(1); namStack.push('C'); namStack.push('C'); namStack.push('C'); namStack.push('B'); namStack.push('B'); namStack.push('B'); namStack.push('A'); namStack.push('A'); namStack.push('A'); scoreStack.push(10); scoreStack.push(15); scoreStack.push(20); cout<<" Id, name and quiz score:\n"; for (int i=0; i<3;i++) { cout <<idStack.pop()<<"\t"<<namStack.pop()<<namStack.pop()<<namStack.pop()<<"\t"<<scoreStack.pop()<<endl; } return 0; }
run
|
edit
|
history
|
help
0
Test 1(2021)
2
search_n algorithm
Cyclically rotate an array by one
Rotate90
infections.cpp
MoaJhalMury
Operators
Test 12(2021)
float