Skip to content

Commit 3e8dac2

Browse files
committed
display works for higher values
1 parent 450d15c commit 3e8dac2

File tree

3 files changed

+29
-50
lines changed

3 files changed

+29
-50
lines changed

src/algorithm/Algorithm.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ public Algorithm(GuiController gui, List<Double> list) {
1818
}
1919

2020
public void draw() {
21-
Platform.runLater(new Runnable() {
22-
@Override
23-
public void run() {
24-
gui.drawArray();
25-
// write() is for testing
26-
write();
27-
}
21+
Platform.runLater(() -> {
22+
gui.drawArray();
23+
// write() is for testing
24+
// write();
2825
});
2926
try {
3027
Thread.sleep(175);
@@ -68,11 +65,8 @@ protected Task<Void> createTask() {
6865
protected Void call() {
6966
try {
7067
sort();
71-
Platform.runLater(new Runnable() {
72-
@Override
73-
public void run() {
74-
unlock();
75-
}
68+
Platform.runLater(() -> {
69+
unlock();
7670
});
7771
} catch (Exception e) {
7872

src/algorithm/QuickSort.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
import java.util.List;
66
import java.util.Stack;
77

8-
public class QuickSort extends Algorithm{
8+
public class QuickSort extends Algorithm {
99

1010
private final Stack<Integer> stack;
11-
11+
1212
public QuickSort(GuiController gui, List<Double> list) {
1313
super(gui, list);
1414
stack = new Stack<>();
1515
}
16-
16+
1717
@Override
1818
protected void sort() {
1919
sort(getList());
2020
}
21-
22-
private void sort(List<Double> list){
23-
if(list.size() > 1){
21+
22+
private void sort(List<Double> list) {
23+
if (list.size() > 1) {
2424
stack.push(0);
25-
stack.push(list.size() -1);
26-
while(!stack.isEmpty()){
25+
stack.push(list.size() - 1);
26+
while (!stack.isEmpty()) {
2727
int end = stack.pop();
2828
int start = stack.pop();
2929
int mid = partition(list, start, end);
@@ -38,7 +38,7 @@ private void sort(List<Double> list){
3838
}
3939
}
4040
}
41-
41+
4242
private int partition(List<Double> list, int low, int high) {
4343
double pivot = list.get(high);
4444

@@ -56,5 +56,5 @@ private int partition(List<Double> list, int low, int high) {
5656
Collections.swap(list, i + 1, high);
5757
draw();
5858
return i + 1;
59-
}
59+
}
6060
}

src/graphics/GuiController.java

+13-28
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
package graphics;
22

3-
import algorithm.Algorithm;
4-
import algorithm.BitonicSort;
5-
import algorithm.BubbleSort;
6-
import algorithm.CoctailSort;
7-
import algorithm.CombSort;
8-
import algorithm.CycleSort;
9-
import algorithm.HeapSort;
10-
import algorithm.InsertionSort;
11-
import algorithm.IterativeQuickSort;
12-
import algorithm.RecursiveMergeSort;
13-
import algorithm.MergeSort;
14-
import algorithm.OddEvenSort;
15-
import algorithm.PancakeSort;
16-
import algorithm.QuickSort;
17-
import algorithm.RecursiveBubbleSort;
18-
import algorithm.RecursiveInsertionSort;
19-
import algorithm.RecursiveQuickSort;
20-
import algorithm.SelectionSort;
21-
import algorithm.ShellSort;
22-
import algorithm.StoogeSort;
3+
import algorithm.*;
234
import java.io.BufferedReader;
245
import java.io.File;
256
import java.io.FileReader;
@@ -32,6 +13,7 @@
3213
import javafx.event.ActionEvent;
3314
import javafx.fxml.FXML;
3415
import javafx.fxml.Initializable;
16+
import javafx.geometry.Pos;
3517
import javafx.scene.control.Button;
3618
import javafx.scene.control.ChoiceBox;
3719
import javafx.scene.control.Label;
@@ -56,13 +38,13 @@ public class GuiController implements Initializable {
5638
private Button restoreB;
5739

5840
private List<Double> list;
59-
private int wid = 10;
60-
private int hei = 10;
41+
private double wid = 10;
42+
private double hei = 10;
6143
private Stage stage;
6244
private FileChooser fileChooser;
6345
private Algorithm algorithm;
6446
private double min;
65-
private final double multiplier = 1.1;
47+
private final double multiplier = 1.5;
6648
private File openedFile;
6749

6850
@Override
@@ -71,7 +53,8 @@ public void initialize(URL url, ResourceBundle rb) {
7153
"Insertion sort", "Iterative quick sort", "Merge sort", "Odd-Even sort", "Pancake sort",
7254
"Quick sort", "Recursive bubble sort", "Recursive insertion sort", "Recursive merge sort", "Recursive Quick sort",
7355
"Selection sort", "Shell sort", "Stooge sort");
74-
// sortingAlgorithm.getItems().addAll("Quick sort end", "Recursive Quick sort end");
56+
// sortingAlgorithm.getItems().add("Quick sort");
57+
sortingAlgorithm.setValue("Quick sort");
7558
startB.setDisable(true);
7659
list = new ArrayList<>();
7760
}
@@ -84,8 +67,8 @@ public void calculateSizeMultipliers() {
8467
} else {
8568
min = Math.abs(min);
8669
}
87-
wid = (int) (display.getWidth() / list.size());
88-
hei = (int) (display.getHeight() / ((double) Collections.max(list) + multiplier * min));
70+
wid = display.getWidth() / list.size();
71+
hei = display.getHeight() / ((double) Collections.max(list) + multiplier * min);
8972
}
9073
}
9174

@@ -100,8 +83,10 @@ public void drawArray() {
10083
display.getChildren().add(r);
10184
Label label = new Label(list.get(i).toString());
10285
label.setFont(new Font(16));
103-
label.setLayoutX(wid * i + wid / 3);
86+
label.setLayoutX(wid * i);
10487
label.setLayoutY((display.getHeight()) - (hei * (list.get(i) + multiplier * min)) / 2);
88+
label.setPrefWidth(wid);
89+
label.setAlignment(Pos.CENTER);
10590
display.getChildren().add(label);
10691
}
10792
}
@@ -155,7 +140,7 @@ private void loadFromFile() {
155140
}
156141
}
157142
}
158-
143+
159144
@FXML
160145
private void loadArray(ActionEvent event) {
161146
// create fileChooser to open txt file

0 commit comments

Comments
 (0)