3
3
import java .io .BufferedReader ;
4
4
import java .io .FileReader ;
5
5
import java .io .IOException ;
6
- import java .util .ArrayList ;
7
6
import java .util .EmptyStackException ;
8
- import java .util .List ;
9
7
10
8
/**
11
9
* Created by IntelliJ IDEA.
@@ -57,40 +55,26 @@ public static boolean isWellFormed(String input) {
57
55
58
56
return stack .isEmpty ();
59
57
}
60
-
61
- /**
62
- * Checks if the parenthesis are well-formed for the entire input.
63
- *
64
- * @param filePath
65
- */
66
- public static void areParenthesisWellFormed (String filePath ) {
67
- List <String > input = readFile (filePath );
68
- for (int i = 0 ; i < input .size (); i ++) {
69
- System .out .println (isWellFormed (input .get (i )) ? "True" : "False" );
70
- }
71
- }
72
-
58
+
73
59
/**
74
- * Reads the file specified in {@param filePath}.
60
+ * Reads the file specified in {@param filePath} line by line
61
+ * and checks if parenthesis are well-formed or not.
75
62
*
76
63
* @param filePath
77
- * @return list of strings in each line of the file
78
64
*/
79
- public static List < String > readFile (String filePath ) {
65
+ public static void readFile (String filePath ) {
80
66
81
- List <String > input = new ArrayList <>();
82
67
try (BufferedReader br = new BufferedReader (new FileReader (filePath ))) {
83
68
84
69
String line ;
85
70
86
71
while ((line = br .readLine ()) != null ) {
87
- input . add ( line );
72
+ System . out . println ( isWellFormed ( line ) ? "True" : "False" );
88
73
}
89
74
90
75
} catch (IOException e ) {
91
76
e .printStackTrace ();
92
77
}
93
- return input ;
94
78
}
95
79
96
80
/**
@@ -99,7 +83,7 @@ public static List<String> readFile(String filePath) {
99
83
* @param a
100
84
*/
101
85
public static void main (String a []) {
102
- areParenthesisWellFormed (a [0 ]);
86
+ readFile (a [0 ]);
103
87
System .exit (0 );
104
88
}
105
89
}
0 commit comments