Question: Consider the following partial definition of an integer stack, along with a partially defined List class. class Stack { public: bool push ( int x

Consider the following partial definition of an integer stack, along with a partially defined List class.
class Stack {
public:
bool push(int x); // push an element, return true if successful.
bool pop(int & x); // pop an element, return true if successful.
private:
List SL;
};
template
class List {
public:
// insert, remove, and append return true if they are successful,
// and they return false if they are unsuccessful.
bool insert(const T &x); // Insert x just to the right of the fence
bool remove(T &x); // Remove x (from just to the right of fence)
bool append(const T &x); // Insert x at the end of the list
void setStart(); // Place fence at list start
void setEnd(); // Place fence at list end
void setPos(int p); // Place fence at position p
void next(); // move fence one place right
void prev(); // move fence one place left
bool getValue(T &x)// Returns TRUE if a value is there, and the
// value is passed back in x. Else return FALSE.
};
Using the list operations defined in the partial interface above and knowing how stacks are supposed to operate, complete the definitions of the operations push and pop using only the available List functions. That is, there is a "HasA" relationship where a stack has a list. Write the code so that the functions run as quickly as possible, assuming the List is an array-based List.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!