We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8e127c commit de71b09Copy full SHA for de71b09
Sorting/insertionsort.java
@@ -0,0 +1,28 @@
1
+/* Created by Jacob Rodgers
2
+ 10/11/17
3
+ */
4
+
5
+ public class insertionSort {
6
7
+ public void iSort(int userArray[]){
8
+ for (int i = 1; i < userArray.length; i++){
9
+ //create an index variable for tracking current number
10
+ int index = userArray[i];
11
+ //and a second counting variable, j
12
+ int j = i - 1;
13
14
+ //Iterate through entire Array comparing each variable to the index assigned above
15
+ while ((j >= 0) && (userArray[j] > index)) {
16
+ //If there is a number out of order then we will switch them
17
+ userArray[j+1] = userArray[j];
18
+ j = j - 1;
19
+ }
20
+ userArray[j+1] = index;
21
22
23
24
25
26
27
28
0 commit comments