-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbrackets.cpp
More file actions
74 lines (60 loc) · 840 Bytes
/
Copy pathbrackets.cpp
File metadata and controls
74 lines (60 loc) · 840 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<cstdio>
#include "Stack.cpp"
bool check(char ch[])
{
int i=0;
char c;
Stack <char> ob;
for(i=0 ; ch[i]!='\0' ; i++)
{
if(ch[i]=='{' || ch[i]=='[' || ch[i]=='(' )
{
ob.push(ch[i]);
}
else if(ch[i]=='}')
{
c=ob.pop();
if(c!= '{')
{
return false;
}
}
else if(ch[i]==']')
{
c=ob.pop();
if(c!='[')
{
return false;
}
}
else if(ch[i]==')')
{
c=ob.pop();
if(c!='(')
{
return false;
}
}
}
if(ob.isEmpty())
return true;
else
return false;
}
int main()
{
int i=0;
char ch[50];
cout<<"Enter Expression :";
cin.getline(ch,50);
if(check(ch))
{
cout<<"\n Entered Expression is Valid ";
}
else
{
cout<<"\n Entered Expression is Invalid ";
}
return 0;
}