Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Modify the code of Figure 4.18 ( in eBook) to support storing variable-length strings of at most 255 characters. The stack array should have type

image text in transcribed

Modify the code of Figure 4.18 ( in eBook) to support storing variable-length strings of at most 255 characters. The stack array should have type char. A string is represented by a series of characters (one character per stack element), with the length of the string stored in the stack element immediately above the string itself, as illustrated by the figure below. The code should accept an input string from, {,},(,),[,] and whether the pairs and the orders of {,},(,),[,] are correct in exp.

For example, the program should print true for exp = [()]{}{[()()]()} and false for exp = [(])

Note: You need to submit the source code and the output please build on the code from 4.18 please code this in C++ and use the code provided above.

11 Array-based stack implementation template class AStack: public Stack { private: int maxSize; // Maximum size of stack int top; // Index for top element Elem listArray; // Array holding stack elements public: AStack (int size =DefaultListSize) // Constructor { maxSize = size; top = 0; listArray = new Elem[size]; } "AStack() { delete [] listArray; } // Destructor void clear() { top = 0; } // Reinitialize void push (const Elem& it) { // Put "it" on stack Assert (top != maxSize, "Stack is full"); listArray[top++] = it; ) Elem pop() { // Pop top element Assert (top != 0, "Stack is empty"); return listArray[--top]; } const Elem& topValue() const { // Return top element Assert (top != 0, "Stack is empty"); return listArray[top-1); } int length() const { return top; } // Return length }; Figure 4.18 Array-based stack class implementation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students explore these related Databases questions