Skip to content

Instantly share code, notes, and snippets.

@sheroze1123
Created March 19, 2016 03:28
Show Gist options
  • Save sheroze1123/f12021c5c126147366bf to your computer and use it in GitHub Desktop.
Save sheroze1123/f12021c5c126147366bf to your computer and use it in GitHub Desktop.
use io
use conv
sort(a: int[]) {
i:int = 0
n:int = length(a)
while (i < n) {
j:int = i
println("j = " + unparseInt(j));
while (j > 0) {
if (a[j-1] > a[j]) {
println("Before swap: " + unparseInt(a[j-1]) + "," + unparseInt(a[j]));
swap:int = a[j]
a[j] = a[j-1]
a[j-1] = swap
println("After swap: " + unparseInt(a[j-1]) + "," + unparseInt(a[j]));
}
j = j-1
}
println("{3,2,1} sorted is {" + unparseInt(a[0]) + "," + unparseInt(a[1]) + "," + unparseInt(a[2]) + "}");
i = i+1
}
}
main(args:int[][]) {
c:int[] = {3,2,1}
println(unparseInt(length(c)));
sort(c);
print("{3,2,1} sorted is {" + unparseInt(c[0]) + "," + unparseInt(c[1]) + "," + unparseInt(c[2]) + "}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment