Stacks problem
Hi everyone,
I'll say upfront that yes this is a homework problem, and I am having trouble with it.
The program should print:
Line 1: Evenly matched parentheses
Line 2: 3 extra right parentheses
Line 3: 2 extra left parentheses
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <cstdlib>
using namespace std;
#include "Stack.h"
Stack::Stack()
: myTop(-1)
{}
bool Stack::empty() const
{
return (myTop == -1);
}
void Stack::push(const StackElement & value)
{
if (myTop < STACK_CAPACITY - 1)
{
++myTop;
myArray[myTop] = value;
}
else
{
cerr << "*** Stack full -- can't add new value ***\n"
"Must increase value of STACK_CAPACITY in Stack.h\n";
exit(1);
}
}
void Stack::display(ostream & out) const
{
for (int i = myTop; i >= 0; i--)
out << myArray[i] << endl;
}
StackElement Stack::top() const
{
if ( !empty() )
return (myArray[myTop]);
else
{
cerr << "*** Stack is empty -- returning garbage value ***\n";
StackElement garbage = 0;
return garbage;
}
}
void Stack::pop()
{
if ( !empty() )
myTop--;
else
cerr << "*** Stack is empty -- can't remove a value ***\n";
}
|
The string is abc (def) x ((azy)(xyz)) ma (def) x azy) bdf) mno) qaa ( bcd ) (( zzyz
Many many thanks,
fooduelajgingdi
Last edited on
Topic archived. No new replies allowed.