forked from D3v3sh5ingh/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParanthesis Matching.cpp
More file actions
65 lines (56 loc) · 868 Bytes
/
Paranthesis Matching.cpp
File metadata and controls
65 lines (56 loc) · 868 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
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
using namespace std;
char stack[100];
int top=0;
void push(char ch)
{
stack[top++]=ch;
}
char pop()
{
return stack[--top];
}
bool check(char x, char y)
{
if ((x=='(' && y==')') || (x=='{' && y=='}') || (x=='[' && y==']') || (x=='<' && y=='>'))
{
return true;
}
else
{
return false;
}
}
int main()
{
char exp[100];
cout<<"Enter The Expression : ";
gets(exp);
for (int i = 0; i < strlen(exp); i++)
{
if (exp[i]=='(' || exp[i]=='{' || exp[i]=='[' || exp[i]=='<')
{
push(exp[i]);
}
else if (exp[i]==')' || exp[i]=='}' || exp[i]==']' || exp[i]=='>')
{
if(!check(pop(), exp[i]))
{
cout<<"\nWrong Expression";
exit(0);
}
}
}
if(top==0)
{
cout<<"Correct Expression";
}
else
{
cout<<"\nWrong Expression";
}
return 0;
}