Question: Modify the code below for the abstract stack type to use a linked list representation. Must be in C++ class Stack { private: int *stackPtr;

Modify the code below for the abstract stack type to use a linked list representation. Must be in C++

class Stack {

private:

int *stackPtr;

int maxLen;

int topSub;

public:

stack(){

stackPtr = new int [100];

maxLen = 99;

topSub = -1;

}

Stack() {delete [] stackPtr;};

void push(int number){

if(topSub == maxLen)

cerr << "Error in push--stack is full ";

else stackPtr[++topSub] = number;

}

void pop(){

if(empty())

cerr << "Error in pop--stack is empty "

else topSub--;

}

int top(){

if(empty())

cerr << "Error in top--stack is empty ";

else

return (stackPtr[topSub]);

}

int empty() {return (topSub == -1);}

}

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 Databases Questions!