Created
January 10, 2018 14:51
-
-
Save mknorth/745113301a8891a51723164ccc73c177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework6; | |
public class SortingAlgorithms { | |
public static void main(String[] args) { | |
int[] arr = {0,-2,3,4,235,35,36,36,23,3}; | |
int temp,j; | |
for(int i = 0; i < arr.length - 1; i++){ | |
if (arr[i] > arr[i + 1]) { | |
temp = arr[i + 1]; | |
arr[i + 1] = arr[i]; | |
j = i; | |
while (j > 0 && temp < arr[j - 1]) { | |
arr[j] = arr[j - 1]; | |
j--; | |
} | |
arr[j] = temp; | |
//System.out.println("arr[j]: " + arr[j] + " " + "j: " + j); | |
} | |
} | |
for(int sr:arr){ | |
System.out.println("sr: " + sr); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment