@@ -10,9 +10,25 @@ const { StdOut, In } = require('../../libs')
10
10
* @see [edu.princeton.cs.algs4.Multiway.java]{@link https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Multiway.java.html}
11
11
*/
12
12
class Multiway {
13
+ /**
14
+ * Creates `n` streams `In` for each given file path
15
+ * that contains an ordered sequence of chars,
16
+ * then it merges all of them in sorted order.
17
+ * @example <caption>Merging 3 sorted source files</caption>
18
+ * {@lang bash}
19
+ * $ ./client Multiway algs4-data/m1.txt algs4-data/m2.txt algs4-data/m3.txt
20
+ * A A B B B C D E F F G H I I J N P Q Q Z
21
+ * @param {...string } args - The file paths: `['path/1', 'path/2', ..., 'path/n']`
22
+ */
23
+ static main ( args ) {
24
+ const streams = args . map ( file => new In ( file ) )
25
+
26
+ this . merge ( streams )
27
+ }
28
+
13
29
/**
14
30
* Given some ordered streams, it merges all of them
15
- * in order printing out the sequence in the `StdOut`.
31
+ * in order, printing out the sequence in the `StdOut`.
16
32
* @param {Array<In> } streams - The array of `In` streams.
17
33
*/
18
34
static merge ( streams ) {
@@ -35,21 +51,6 @@ class Multiway {
35
51
}
36
52
}
37
53
}
38
-
39
- /**
40
- * Creates n `In` streams depending on the given file paths,
41
- * then it merges them in sorted order.
42
- * @param {...string } args - The file paths.
43
- * @example <caption>Merging 3 sorted source files</caption>
44
- * {@lang bash}
45
- * $ ./client Multiway algs4-data/m1.txt algs4-data/m2.txt algs4-data/m3.txt
46
- * A A B B B C D E F F G H I I J N P Q Q Z
47
- */
48
- static main ( args ) {
49
- const streams = args . map ( file => new In ( file ) )
50
-
51
- this . merge ( streams )
52
- }
53
54
}
54
55
55
56
module . exports = { Multiway }
0 commit comments