-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLT_Stacks_EspanoIsidroNavarro_DSA.cpp
More file actions
50 lines (44 loc) · 1.06 KB
/
Copy pathLT_Stacks_EspanoIsidroNavarro_DSA.cpp
File metadata and controls
50 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*Learning Task - Stacks
Espano, Kyla Caryl B.
Isidro, Mary Grace
Navarro, Maria Cleofe R.
*/
#include <bits/stdc++.h>
using namespace std;
//Boolean type of function where the return value type is true/false.
bool balancedBracket(string bracket)
{
stack<char> esin;
for (int i = 0; i < bracket.length(); i++) {
if (esin.empty()) {
esin.push(bracket[i]);
}
else if ((esin.top() == '(' && bracket[i] == ')')
|| (esin.top() == '{' && bracket[i] == '}')
|| (esin.top() == '[' && bracket[i] == ']')) {
esin.pop();
}
else {
esin.push(bracket[i]);
}
}
if (esin.empty()) {
return true;
}
return false;
}
//Main function
int main()
{
string bracket;
int d;
cout << "Input Data:";
cin >> d;
for (int i = 0; i<d; i++){
cin >> bracket;
if (balancedBracket(bracket))
cout << "Balanced\n";
else
cout << "Not Balanced\n";
}
}