Skip to content

Commit 4771c10

Browse files
committed
Initial Commit
1 parent ee1d5a2 commit 4771c10

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed
Binary file not shown.

src/sortingVisualizer/Controller.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
8686

8787
aboutBtn.setOnMouseClicked(e -> {
8888
Alert alert = new Alert(Alert.AlertType.INFORMATION);
89-
alert.setTitle("About Sorting Visualizer & Developer");
90-
alert.setHeaderText("Developed & Programmed by Gagan Bhatia");
91-
alert.setContentText("Visualize Bubble Sort Algorithm, Insertion Sort Algorithm, Selection Sort Algorithm, Quick Sort Algorithm & Merge Sort Algorithm");
92-
alert.setGraphic(new ImageView());
89+
alert.setTitle("About Application & Developer");
90+
alert.setHeaderText("Developed by Gagan Bhatia");
91+
alert.setContentText("Visualize Bubble Sort Algorithm, Insertion Sort Algorithm, Selection Sort Algorithm, Shell Sort, Quick Sort Algorithm & Merge Sort Algorithm and see how these work.\n\nTip: If size of array is larger make sure that you decrease the delay time!");
9392
alert.show();
9493
});
9594

@@ -396,7 +395,6 @@ private void quickSort() {
396395
isArraySorted(true);
397396
}).start();
398397
}
399-
400398
private void quickSortRec(int startIdx, int endIdx) {
401399
int idx = partition(startIdx, endIdx);
402400

@@ -408,7 +406,6 @@ private void quickSortRec(int startIdx, int endIdx) {
408406
quickSortRec(idx, endIdx);
409407
}
410408
}
411-
412409
private int partition(int left, int right) {
413410
barsDisableEffect(left, right);
414411
int pivot = (int) ((XYChart.Data) series.getData().get(left)).getYValue();
@@ -491,44 +488,40 @@ private void mergeOperation(int low, int mid, int high) {
491488
delay();
492489
if ((int) ((XYChart.Data) series.getData().get(i)).getYValue() < (int) ((XYChart.Data) series.getData().get(j)).getYValue()) {
493490
((XYChart.Data) copySeries.getData().get(k)).setYValue(((XYChart.Data) series.getData().get(i)).getYValue());
494-
delay();
495491
i++;
496492
k++;
497493
} else {
498-
((XYChart.Data) copySeries.getData().get(k)).setYValue(
499-
((XYChart.Data) series.getData().get(j)).getYValue());
500-
delay();
494+
((XYChart.Data) copySeries.getData().get(k)).setYValue(((XYChart.Data) series.getData().get(j)).getYValue());
501495
j++;
502496
k++;
503497
}
504498
changeStyleEffect(i, MAIN_THEME, j, MAIN_THEME);
505499
}
506500
for (; i <= mid; i++) {
507-
((XYChart.Data) copySeries.getData().get(k)).setYValue(
508-
((XYChart.Data) series.getData().get(i)).getYValue());
509-
delay();
501+
((XYChart.Data) copySeries.getData().get(k)).setYValue(((XYChart.Data) series.getData().get(i)).getYValue());
510502
k++;
511503
}
512504
for (; j <= high; j++) {
513-
((XYChart.Data) copySeries.getData().get(k)).setYValue(
514-
((XYChart.Data) series.getData().get(j)).getYValue());
515-
delay();
505+
((XYChart.Data) copySeries.getData().get(k)).setYValue(((XYChart.Data) series.getData().get(j)).getYValue());
516506
k++;
517507
}
518508

519509
for (int x = low; x <= high; x++) {
520510
int finalX = x;
521511
changeStyleEffect(finalX,MAIN_THEME);
522-
((XYChart.Data) series.getData().get(x)).setYValue(
523-
((XYChart.Data) copySeries.getData().get(x)).getYValue());
512+
((XYChart.Data) series.getData().get(x)).setYValue(((XYChart.Data) copySeries.getData().get(x)).getYValue());
524513
delay();
525514
}
526515
}
527516

517+
518+
// for swap Animation effect
528519
private ParallelTransition swapAnimation(int d1, int d2) {
520+
// get the precise location of the node in X axis
529521
double a1 = ((XYChart.Data) series.getData().get(d1)).getNode().getParent().localToParent(((XYChart.Data) series.getData().get(d1)).getNode().getBoundsInParent()).getMinX();
530522
double a2 = ((XYChart.Data) series.getData().get(d1)).getNode().getParent().localToParent(((XYChart.Data) series.getData().get(d2)).getNode().getBoundsInParent()).getMinX();
531523

524+
// if any swap occur then we get the location of our node where it is swapped
532525
double translated1 = ((XYChart.Data) series.getData().get(d1)).getNode().getTranslateX();
533526
double translated2 = ((XYChart.Data) series.getData().get(d2)).getNode().getTranslateX();
534527

@@ -537,6 +530,7 @@ private ParallelTransition swapAnimation(int d1, int d2) {
537530
TranslateTransition t2 = new TranslateTransition(Duration.millis(DELAY_TIME), ((XYChart.Data) series.getData().get(d2)).getNode());
538531
t2.setByX(a1 - a2);
539532
ParallelTransition pt = new ParallelTransition(t1, t2);
533+
// ParallelTransition will run t1 and t2 in parallel
540534
pt.statusProperty().addListener((e, old, curr) -> {
541535
if (old == Animation.Status.RUNNING) {
542536
((XYChart.Data) series.getData().get(d2)).getNode().setTranslateX(translated1);

0 commit comments

Comments
 (0)