Ok, this is pretty much what i have so far....it works on some cases...but when i try to implement other strings, it gives me a windows error..no compile errors...here is the code i have so far...
Code:
#include <stack>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
stack<char> charStack;
char cChar;
ifstream inFile;
inFile.open("infile.txt");
if(!inFile)
{
cout<<"Input file does not exist."<<endl;
return 1;
}
inFile>>cChar;
while(inFile)
{
if (cChar == '{' || cChar == '[' || cChar == '(')
{
charStack.push(cChar);
}
else
{
if (charStack.top() == '(')
{
if (cChar == ')')
{
charStack.pop();
}
}
else if (charStack.top() == '[')
{
if(cChar == ']')
{
charStack.pop();
}
}
else if (charStack.top() == '{')
{
if(cChar == '}')
{
charStack.pop();
}
}
}
inFile>>cChar;
}
if(charStack.empty())
{
cout<<endl<<"Valid"<<endl;
}
else
{
cout<<endl<<"Invalid"<<endl;
}
cin.get();
return 0;
}
when i use these input files, I get a valid output....
Code:
input:
{(a+5)-7*[1-{4/2}])/{2*(3-6)} //invalid
input:
(((({[]})()()))){} //valid
input:
{{()} //invalid
and i get windows errors on the following
Code:
input:
{()[()]}}
input:
{{a+5}-7*[1-{4/2}]}/{2*(3-6)}
HELP!!!