-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.java
More file actions
218 lines (171 loc) · 4.32 KB
/
Copy pathdisplay.java
File metadata and controls
218 lines (171 loc) · 4.32 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
public class display {
public String content;
public Sort sort = null;
boolean ft = true;
public void get_file_data(String path) {
try {
Path Input_data = Paths.get(path);
content = Files.readString(Input_data);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void get_random_string(int amount, int n1, int n2) {
try {
ArrayList<String> al = new ArrayList<String>();
sort = new Sort();
sort.randomString(amount, n1, n2);
File f = new File("data.txt");
al = sort.getDataset();
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < al.size(); i++) {
bw.write(al.get(i) + " ");
bw.flush();
}
bw.close();
Path Input_data = Paths.get("data.txt");
content = Files.readString(Input_data);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void get_random_num(int amount, double n1, double n2) {
try {
ArrayList<String> al = new ArrayList<String>();
sort = new Sort();
sort.randomNumber(amount, n1, n2);
File f = new File("data.txt");
al = sort.getDataset();
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < al.size(); i++) {
bw.write(al.get(i) + " ");
bw.flush();
}
bw.close();
Path Input_data = Paths.get("data.txt");
content = Files.readString(Input_data);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void reset_data() {
try {
File f = new File("data.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write("");
bw.flush();
bw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
ft = true;
}
public void reset_ft() {
ft = true;
}
public void start_asort(int type, String data) {
ArrayList<String> input = new ArrayList<String>();
Scanner sc = new Scanner(data);
while (sc.hasNext()) {
input.add(sc.next());
}
sc.close();
content = "";
if (type == 0) {
sort = new Insertion(input);
sort.aStepByStep();
ArrayList<String> al = new ArrayList<String>();
al = sort.getResult();
for (int i = 0; i < al.size(); i++) {
content += al.get(i) + "\n\r";
}
} else if (type == 1) {
sort = new Selection(input);
sort.aStepByStep();
ArrayList<String> al = new ArrayList<String>();
al = sort.getResult();
for (int i = 0; i < al.size(); i++) {
content += al.get(i) + "\n\r";
}
}
}
public void start_dsort(int type, String data) {
ArrayList<String> input = new ArrayList<String>();
Scanner sc = new Scanner(data);
while (sc.hasNext()) {
input.add(sc.next());
}
sc.close();
content = "";
if (type == 0) {
sort = new Insertion(input);
sort.dStepByStep();
ArrayList<String> al = new ArrayList<String>();
al = sort.getResult();
for (int i = 0; i < al.size(); i++) {
content += al.get(i) + "\n\r";
}
} else if (type == 1) {
sort = new Selection(input);
sort.dStepByStep();
ArrayList<String> al = new ArrayList<String>();
al = sort.getResult();
for (int i = 0; i < al.size(); i++) {
content += al.get(i) + "\n\r";
}
}
}
public int get_size(String data) {
ArrayList<String> input = new ArrayList<String>();
Scanner sc = new Scanner(data);
while (sc.hasNext()) {
input.add(sc.next());
}
sc.close();
return input.size();
}
public void get_previous_result(int type, String data) {
if (type == 0)
content = sort.previous();
else if (type == 1)
content = sort.previous();
}
public void get_next_result(int ad,int type, String data) {
if (ft) {
ArrayList<String> input = new ArrayList<String>();
Scanner sc = new Scanner(data);
while (sc.hasNext()) {
input.add(sc.next());
}
sc.close();
if (type == 0)
sort = new Insertion(input);
else if (type == 1)
sort = new Selection(input);
ft = false;
}
if (ad == 0) {
if (type == 0)
content = sort.aNext();
else if (type == 1)
content = sort.aNext();
}else if(ad == 1) {
if (type == 0)
content = sort.dNext();
else if (type == 1)
content = sort.dNext();
}
}
public String get_content() {
return content;
}
}