Skip to content

Instantly share code, notes, and snippets.

@schani
Created July 14, 2010 11:13
Show Gist options
  • Select an option

  • Save schani/475297 to your computer and use it in GitHub Desktop.

Select an option

Save schani/475297 to your computer and use it in GitHub Desktop.
using System;
public class Sort {
static void maxSort (int[] arr) {
int len = arr.Length;
for (int i = 1; i < len; ++i) {
for (int j = i; j > 0; --j) {
if (arr [j-1] > arr [j]) {
/* swap */
int tmp = arr [j-1];
arr [j-1] = arr [j];
arr [j] = tmp;
} else {
/* inner loop done */
break;
}
}
}
}
static void printArr (int[] arr) {
for (int i = 0; i < arr.Length; ++i)
Console.Write ("" + arr [i] + " ");
Console.WriteLine ("");
}
public static int Main () {
Random r = new Random ();
int[] arr = new int [32];
for (int i = 0; i < arr.Length; ++i)
arr [i] = r.Next (100);
printArr (arr);
maxSort (arr);
printArr (arr);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment