Skip to content

Commit 950553d

Browse files
committed
Added Selectionsort
1 parent 96be31a commit 950553d

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

Binary file not shown.

src/com/marcomsl/algorithmvisualization/AlgorithmVisualizer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,23 @@ public void insertionSort(int animationSpeed) throws InterruptedException {
7979
}
8080
}
8181

82+
public void selectionSort(int animationSpeed) throws InterruptedException {
83+
int highestIndex, tempValue;
84+
for (int i = array.length - 1; i >= 0; i--) {
85+
highestIndex = i;
86+
for (int j = 0; j <= i; j++) {
87+
if (array[j] > array[highestIndex]) {
88+
highestIndex = j;
89+
}
90+
}
91+
92+
Thread.sleep(animationSpeed);
93+
tempValue = array[highestIndex];
94+
array[highestIndex] = array[i];
95+
array[i] = tempValue;
96+
}
97+
98+
}
99+
82100

83101
}

src/com/marcomsl/algorithmvisualization/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Main {
77
public static void main(String[] args) throws InterruptedException {
88

99
AlgorithmVisualizer algorithmVisualizer = new AlgorithmVisualizer(50);
10-
algorithmVisualizer.insertionSort(25);
10+
algorithmVisualizer.selectionSort(100);
1111
algorithmVisualizer.resetArray();
1212
algorithmVisualizer.bubblesort(15);
1313
}

0 commit comments

Comments
 (0)