Question: 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 can you help, the question is in the second capture // Array-based

stack implementation template class AStack: public Stack { private: int maxSize; //

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

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!