Im trying to do this project for my class. I have my code but I know its not right. So I was hoping someone could help me out or at least point me in the right direction. I have to write a program in C++ that checks various lines of text (taken as arithmetical expressions) to see if the following 3 pairs of grouping symbols: '(', ')', '[', ']', '{', '}' are being used properly. I have to use a Stack with the array implementation using a class. Then I have to test my program on the following data:
a+b
(a-b)
((c-d)
[(a-b)+(c+d)]
(e+f]
(f+g))
[f-g}
{c+d)
{a*[(c-d)*(e+f)+(g-h)/(f+g)]+h}*b+c
(((((a)))))
Im a beginner and I have read the book but it doesn't help that much. Im using Visual Studio C++ 2010 and here is my code so far:
Code:#include <list>
using namespace
int main();
{
template <class Elem> class Astack: public Stack<Elem> {
private:
int top;
int size;
Elem *listArray;
public:
Astack(int sz =DefaultListSize)
{size = sz; top = 0; listArray = new Elem[sz];}
~Astack() { delete [] listArray;}
void clear() {top = 0;}
bool push(const Elem& item){
if(top == size) return false;/* Stack is full*/
else {listArray [top++] = item;
return true;
}
}
bool pop(Elem& item){
if(top == 0) return false;
else {item = listArray[--top];
return true;
}
}
bool topValue(Elem& item) const {
if (top == 0) return false;
else {item = listArray[top - 1];
return true;
}
}
int length() const {return top;}
bool IsEmpty() const {if(top == 0) return true;
else return false;
};