Parenthesis Check using Stacks

i keep getting the error -Error 4 error C2447: '{' : missing function header (old-style formal list?) Warning 1 warning C4018: '<' : signed/unsigned mismatch \balancedparentheseslab2\parenthesescheck.cpp 23

Warning 2 warning C4101: 'res' : unreferenced local variable \balancedparentheseslab2\parenthesescheck.cpp 56 1
BalancedParenthesesLab2
Warning 3 warning C4101: 'top' : unreferenced local variable \balancedparentheseslab2\parenthesescheck.cpp 57 1 BalancedParenthesesLab2


[/code]
#include<iostream>
#include<stack>
#include<string>
using namespace std;
// Function to check whether two characters are opening
// and closing of same type.
bool ArePair(char opening,char closing)
{
if(opening == '(' && closing == ')') return true;
else if(opening == '{' && closing == '}') return true;
else if(opening == '[' && closing == ']') return true;
return false;
}
bool AreParanthesesBalanced(string exp)
{
stack<char> S;
for(int i =0;i<exp.length();i++)
{
if(exp[i] == '(' || exp[i] == '{' || exp[i] == '[')
S.push(exp[i]);
else if(exp[i] == ')' || exp[i] == '}' || exp[i] == ']')
{
if(S.empty() || !ArePair(S.top(),exp[i]))
return false;
else
S.pop();
}
}
return S.empty() ? true:false;
}

int main()
{

string expression;
cout<<"Enter an expression: ";
cin>>expression;
if(AreParanthesesBalanced(expression))
cout<<"Balanced\n";
else
cout<<"Not Balanced\n";
}


void push(struct sNode** top_ref, int new_data);


int pop(struct sNode** top_ref)
{
char res;
struct sNode*top;
}
/*If stack is empty then error */
{
if(*top_ref == NULL)
cout<<"Stack overflow \n";
else

top = *top_ref;
res = top->data;
*top_ref = top->next;
free(top);
return res;
}

[/code]
Last edited on
Topic archived. No new replies allowed.