Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you help, the question is in the second capture // Array-based stack implementation template class AStack: public Stack { private: int maxSize; // Maximum

can you help, the question is in the second capture image text in transcribed

image text in transcribed

// 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

// 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 =DefaultListsi ze) // Constructor (maxSize - size; top = 0; listArray = new Elem[size]; Astack() (delete UlistArray; } // Destructor void clear() { top = 0; } // Reinitialize void push(const Elem& it) ( // Put "it" on stack Assert (top ImaxSize, "Stack is full"); listArray[top++ - it; Elem pop() // Pop top olement Assert (topo, Stack is empty"); return listArray[--top: const Elem& topValue() const / Return top element Assert (top 1 O, "Stack is empty"); return listArray (top-1); Ant length(const return top: // Return length Figure 4.18 Array-based stack class implementation. 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 = "[0]{}{[0010}" and false for exp = "(0))" 0 1 2 3 4 5 6 7 8 Top=8 Note: You need to submit the source code and the output

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

Step: 3

blur-text-image

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago