File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
src/main/java/sortVisualiser Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 33import java .util .ArrayList ;
44import javax .swing .JFrame ;
55import sortVisualiser .algorithms .BubbleSort ;
6+ import sortVisualiser .algorithms .GnomeSort ;
67import sortVisualiser .algorithms .ISortAlgorithm ;
78import sortVisualiser .algorithms .InsertionSort ;
89import sortVisualiser .algorithms .MergeSort ;
@@ -33,7 +34,8 @@ public SortVisualiser() {
3334 window .setVisible (true );
3435
3536 sortQueue = new ArrayList <>();
36- sortQueue .add (new MergeSort ());
37+ sortQueue .add (new GnomeSort ());
38+ //sortQueue.add(new MergeSort());
3739 //sortQueue.add(new QuickSort());
3840 //sortQueue.add(new SelectionSort());
3941 //sortQueue.add(new InsertionSort());
Original file line number Diff line number Diff line change 1+ package sortVisualiser .algorithms ;
2+
3+ import sortVisualiser .SortArray ;
4+
5+ /**
6+ *
7+ * @author Matthew Hopson
8+ */
9+ public class GnomeSort implements ISortAlgorithm {
10+ @ Override
11+ public void runSort (SortArray array ) {
12+ int index = 0 ;
13+ while (index < array .arraySize ()) {
14+ if (index == 0 ) {
15+ index ++;
16+ }
17+ if (array .getValue (index ) >= array .getValue (index - 1 )) {
18+ index ++;
19+ }
20+ else {
21+ array .swap (index , index - 1 , getDelay ());
22+ index --;
23+ }
24+ }
25+ }
26+
27+ @ Override
28+ public String getName () {
29+ return "Shell sort" ;
30+ }
31+
32+ @ Override
33+ public long getDelay () {
34+ return 5 ;
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments