-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalancedParanthesis.java
More file actions
46 lines (38 loc) · 844 Bytes
/
Copy pathBalancedParanthesis.java
File metadata and controls
46 lines (38 loc) · 844 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
package datastructures;
import bridgelabz.utility.utility;
public class BalancedParanthesis
{
public static void main(String[] args)
{
System.out.println("enter the max size");
int n=utility.getint();
StackLogic stack =new StackLogic(n);
System.out.println();
String exp="(5+6)∗(7+8)/(4+3)(5+6)∗(7+8)/(4+3)";
System.out.println("Matches and Mismatches");
for(int i=0;i<exp.length();i++)
{
char ch=exp.charAt(i);
if(ch=='(')
{
stack.push(i);
}
else if(ch==')')
{
try
{
long p=(stack.pop()+1);
System.out.println(" ')' at index" +(i+1)+ "matched with '(' at index" +p);
}
catch(Exception e)
{
System.out.println(" ')' at index "+ (i+1) + "is un matched");
}
}
while(stack.isEmpty())
{
System.out.println("'(' at index "+ (stack.pop()+1) +" is unmatched");
}
}
}
}