Modify the C++ class for the abstract stack type shown in Section

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 <iostream.h>
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 fulln”;
else stackPtr[++topSub] = number;
}
void pop() {
if (empty())

cerr << “Error in pop–stack is emptyn”;
else topSub–;
}
int top() {
if (empty())
cerr << “Error in top–stack is emptyn”;
else
return (stackPtr[topSub]);
}
int empty() {return (topSub == -1);}
}

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top