-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSortTest.java
More file actions
89 lines (73 loc) · 2.22 KB
/
MergeSortTest.java
File metadata and controls
89 lines (73 loc) · 2.22 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
81
82
83
84
85
86
87
88
89
import java.util.*;
import java.io.*;
public class MergeSortTest{
public static void main(String[] args){
int n = Integer.parseInt(args[0]);
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = 100000 * (i+1);
}
try
{
ArrayList<Float> st = new ArrayList<Float>();
ArrayList<Float> mt = new ArrayList<Float>();
for(int c : arr){
System.out.println(c + ":");
Process gen = Runtime.getRuntime().exec("java RandomNumGenerator " + c);
BufferedReader make = new BufferedReader(new InputStreamReader(gen.getInputStream()));
PrintWriter print = new PrintWriter(new File("nums.txt"));
String line = "";
while ((line = make.readLine()) != null)
{
print.println(line);
}
make.close();
print.close();
Process process = Runtime.getRuntime().exec("java MMergeSort " + c);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
line = null;
while ((line = input.readLine()) != null)
{
System.out.println(" " + line);
Scanner word = new Scanner(line);
if(line.charAt(0)=='S'){
word.next();
word.next();
st.add(Float.parseFloat(word.next()));
}
else{
word.next();
word.next();
word.next();
mt.add(Float.parseFloat(word.next()));
}
word.close();
}
input.close();
}
//Printouts
System.out.println();
System.out.println("Size: ");
for(int c : arr){
System.out.print(c + ", ");
}
System.out.println();
System.out.println();
System.out.println("Single-Threaded: ");
for(Float e : st){
System.out.print(e + ", ");
}
System.out.println();
System.out.println();
System.out.println("Multi-Threaded: ");
for(Float e : mt){
System.out.print(e + ", ");
}
System.out.println();
System.out.println();
}
catch (IOException e){
e.printStackTrace();
}
}
}