Skip to content

Instantly share code, notes, and snippets.

@mknorth
Created January 10, 2018 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mknorth/745113301a8891a51723164ccc73c177 to your computer and use it in GitHub Desktop.
Save mknorth/745113301a8891a51723164ccc73c177 to your computer and use it in GitHub Desktop.
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