Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use only top, pop, and push to implement the following functions: C++ errorCode Stack::pop(){ if(empty()) return underflow; count--; return success; } errorCode Stack::top(stackEntry &item) const{
Use only top, pop, and push to implement the following functions: C++
errorCode Stack::pop(){
if(empty()) return underflow;
count--;
return success;
}
errorCode Stack::top(stackEntry &item) const{
if(empty()) return underflow;
item = entry[count-1];
return success;
}
errorCode Stack::push(const StackEntry &item){
if(full()) return overflow;
entry[count++] = item;
return success;
}
By using only the stack methods, top(), pop(), and push(), that we have implemented in this week, write the following functions: (a) Function bool full(Stack &s) leaves the Stack s unchanged and returns a value of true or false according to whether the Stack s is full or not. (b) Function errorCode topAndPop(Stack &s, stackEntry &t) removes the top entry from the Stack s and returns its value as the output parameter t. (c) Function void clear(Stack &s) deletes all entries and returns s as an empty Stack. (d) Function int size(Stack &s) leaves the Stack s unchanged and returns a count of the number of entries in the Stack. (e) Function void deleteAll(Stack &s, stackEntry x) deletes all occurrences (if any) of x from s and leaves the remaining entries in s in the same relative order. By using only the stack methods, top(), pop(), and push(), that we have implemented in this week, write the following functions: (a) Function bool full(Stack &s) leaves the Stack s unchanged and returns a value of true or false according to whether the Stack s is full or not. (b) Function errorCode topAndPop(Stack &s, stackEntry &t) removes the top entry from the Stack s and returns its value as the output parameter t. (c) Function void clear(Stack &s) deletes all entries and returns s as an empty Stack. (d) Function int size(Stack &s) leaves the Stack s unchanged and returns a count of the number of entries in the Stack. (e) Function void deleteAll(Stack &s, stackEntry x) deletes all occurrences (if any) of x from s and leaves the remaining entries in s in the same relative order
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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