C++ Language C++ Code not working, what is the missing piece in this code? #include #include #include #include using namespace std; int main() { string x; stack < char, vector > iStack; boolean status=true; cout << "Enter series of parentheses: "; getline(cin, x); for (int i=0; i
C++ Language
C++ Code not working, what is the missing piece in this code?
#include <iostream>
#include <string>
#include <
#include <stack>
using namespace std;
int main()
{
string x;
stack < char, vector<char> > iStack;
boolean status=true;
cout << "Enter series of parentheses: ";
getline(cin, x);
for (int i=0; i<x.length(); i++)//measure the length of the string input
if (x[i] == '(' || x[i] == '{' || x[i] == '[')
iStack.push(x[i]);
else
{ //if not opening grouping symbol
if(x[i] == ']') {
if(iStack.isEmpty() || iStack.top() != '[') {
return false;
}
} else if (x[i] == ')') {
if(iStack.isEmpty() || iStack.top() != '(') {
return false;
}
} else if (x[i] == '}') {
if(iStack.isEmpty() || iStack.top() != '{') {
return false;
}
}
iStack.pop();
}
if (iStack.empty())
cout << "Balance!" << endl;
else
cout << "Not Balance!" << endl;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images