Question
I needed to make a function that would reverse a stack. I have the reverse function working, but I need help with making a while
I needed to make a function that would reverse a stack. I have the reverse function working, but I need help with making a while function in the driver to display the information of the stack. both header files and the driver is included.
stackADT.h
#pragma once template
virtual bool isEmptyStack() const = 0;
virtual bool isFullStack() const = 0;
virtual void push(const Type& newItem) = 0;
virtual Type top() const = 0;
virtual void pop() = 0;
};
stackType.h
#pragma once #include
#include"stackADT.h"
using namespace std;
template
void initializeStack();
bool isEmptyStack() const;
bool isFullStack() const;
void push(const Type& newItem);
Type top() const;
void pop();
stackType(int stackSize = 100);
bool operator==(const stackType
stackType(const stackType
~stackType(); //Destructor
void reverseStack(stackType
private: int maxStackSize; int stackTop; Type *list;
void copyStack(const stackType
};
template
template
template
template
} else { cout << "The stack is full." << endl; }
}
template
template
else cout << "Cannot remove from an empty stack." << endl; }
template
stackTop = 0; list = new Type[maxStackSize];
}
template
template
for (int j = 0; j < stackTop; j++) list[j] = otherStack.list[j]; }
template
template
return *this; }
template
template /*for (int i = 0; i < maxStackSize; i++) { cout << list[i] << endl; } cout << "********************************************" << endl; for (int i = 0; i /*template driver.cpp #pragma once #include "stackType.h" #include using namespace std; int main() { int size, number; cout << "What is the size of the stack?" << endl; cin >> size; stackType cout << "Please enter a number: " << endl; cin >> number; while (number != -9999) { stack1.push(number); cout << "Enter a number or -9999 if you you're done:" << endl; cin >> number; } stack2 = stack1; /*if (stack2 == stack1) cout << "These are two identical stacks." << endl; else cout << "These are two different stacks." << endl;*/ for (int i = 0;i /*if (stack2 == stack1) cout << "These are two identical stacks." << endl; else cout << "These are two different stacks." << endl;*/ stack2.reverseStack(stack2); /*for (int j = 0; j < size; j++) { cout << stack2.top() << endl; stack2.pop(); } while (stack2.top() != 0) { cout << stack2.top() << endl; stack2.pop(); }*/ system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started