-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckingParenthesis.java
More file actions
80 lines (80 loc) · 1.93 KB
/
CheckingParenthesis.java
File metadata and controls
80 lines (80 loc) · 1.93 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chapter05;
import java.util.Scanner;
/**
*
* @author harsh
*/
class node1{
int data;
node1 next;
node1(){
data=0;
next = null;
}
}
class stack{
Scanner scan = new Scanner(System.in);
public int x,i=0;
public node1 front;
stack(){
front = null;
}
node1 newNode(){
node1 temp = new node1();
temp.data=1;
temp.next=null;
return temp;
}
void push(){
node1 temp;
temp = newNode();
if(front == null){
System.out.println("First element pushed");
front = temp;
i++;
}else{
temp.next=front;
front=temp;
i++;
System.out.println("Element pushed");
}
}
void pop(){
if(front==null){
System.out.println("Empty Stack");
i--;
}else{
front=front.next;
i--;
System.out.println("Element Poped");
}
}
boolean memory(){
return 0==i;
}
}
public class CheckingParenthesis {
public static void main(String[] args){
stack abc = new stack();
Scanner scan = new Scanner(System.in);
System.out.println("Enter the line");
String string = scan.next();
char[] buf =new char[string.length()];
string.getChars(0, string.length(), buf, 0);
for(char i : buf){
if(i=='{')
abc.push();
if(i=='}')
abc.pop();
}
if(abc.memory())
System.out.println("All the parenthesis are closed");
else
System.err.println("All parenthsis are not closed");
}
}