Question: Modify the C++ class for the abstract stack type shown in Section 11.4.2 to use a linked list representation and test it with the same

Modify the C++ class for the abstract stack type shown in Section 11.4.2 to use a linked list representation and test it with the same code that
appears in this chapter.

C++ class for abstract stack type in section 11.4.2 :

#include
class Stack {
private: //** These members are visible only to other
//** members and friends (see Section 11.6.4)
int *stackPtr;
int maxLen;
int topSub;
public: //** These members are visible to clients
Stack() { //** A constructor
stackPtr = new int [100];
maxLen = 99;
topSub = -1;
}
~Stack() {delete [] stackPtr;}; //** A destructor
void push(int number) {
if (topSub == maxLen)
cerr << "Error in push--stack is full\n";
else stackPtr[++topSub] = number;
}
void pop() {
if (empty())

cerr << "Error in pop--stack is empty\n";
else topSub--;
}
int top() {
if (empty())
cerr << "Error in top--stack is empty\n";
else
return (stackPtr[topSub]);
}
int empty() {return (topSub == -1);}
}

Step by Step Solution

3.31 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include include using namespace std class Stack public Stack stackTop nul... View full answer

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 Concepts of Programming Languages Questions!