I dont no how to fix. Can someone help me out plz. (Please see the picture)
[IMG]http://i61.tinypic.com/2r2cfnq.png[/IMG]
#ifndef DYNINTSTACK_H
#define DYNINTSTACK_H
class DynIntStack
{
private:
// Structure for stack nodes
struct StackNode
{
int value; // Value in the node
StackNode *next; // Pointer to the next node
};
StackNode *top; // Pointer to the stack top
public:
// Constructor
DynIntStack()
{ top = NULL; }
// Destructor
~DynIntStack();
// Stack operations
void push(int);
void pop(int &);
bool bracketsame(char,char);
bool balancedparantheses(string); //checks if parentheses are
bool isEmpty();
};
#endif
#include "DynIntStack.h"
#include <iostream>
#include <string>
using namespace std;
// Main to run program
int main()
{
string expression;
cout<<"Enter an expression to check: ";
cin>>expression;
if(DynIntStack::balancedparantheses(expression))
cout<<"Balanced expression \n";
else
cout<<"Expression is not balanced \n";
}
bool bracketsame(char opening,char closing) // function checks if opening and closing brackets are same
{
if(opening == '(' && closing == ')') return true;
else if(opening == '{' && closing == '}') return true;
else if(opening == '[' && closing == ']') return true;
return false;
}
bool balancedparantheses(string exp) //checks if parentheses are
{ //balanced or not
stack<char> StackNode;
for(int i =0;i<exp.length();i++)
{
if(exp[i] == '(' || exp[i] == '{' || exp[i] == '[')
StackNode.push(exp[i]);
else if(exp[i] == ')' || exp[i] == '}' || exp[i] == ']')
{
if(StackNode.empty() || !bracketsame(StackNode.top(),exp[i]))
return false;
else
StackNode.pop();
}
}
return StackNode.empty() ? true:false;
}