#include <iostream>
//This program works only for parantheses "()".
//Check more to get the program of balanced brackets.
using namespace std;
int is_balanced(char input[])
{
char s[100];
char last;
int top = 0;
for(int i = 0; input[i] != ' '; i++)
{
if(input[i] == '(')
{
s[top] = '(';
top++;
}else if(input[i] == ')')
{
if(top == 0)
{
return 0;
}
top--;
if(s[top] == ')')
{
return 0;
}
}
}
if(top == 0)
{
return 1;
}else
{
return 0;
}
}
int main()
{
char input[100];
cin >> input;
if(is_balanced(input))
{
cout << "Balanced!
";
}else
{
cout << "Imbalanced!
";
}
return 0;
}
Code Example |
---|
:: |
:: |
Cpp :: |
Cpp :: google test assert exception |
:: Reverse a linked list geeksforgeeks in c++ |
:: |
Cpp :: |
:: |
Cpp :: |
:: |
:: |
Cpp :: |
Cpp :: |
Cpp :: minimum characters to make string palindrome |
:: priority queue in cpp |
:: |
:: |
:: |
:: |
:: |
:: pthread c++ example with output |
:: how to get characters through their ascii value in c++ |
:: |
Cpp :: |
Cpp :: |
Cpp :: |
Cpp :: |
:: |
:: c++ vector allocator example |
:: |