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 pushint x; push an element, return true if successful.
bool popint & 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 insertconst T &x; Insert x just to the right of the fence
bool removeT &x; Remove x from just to the right of fence
bool appendconst 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 setPosint p; Place fence at position p
void next; move fence one place right
void prev; move fence one place left
bool getValueT &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 arraybased List.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
