Skip to content

Instantly share code, notes, and snippets.

@martinpinto
Last active August 29, 2015 14:20
Show Gist options
  • Save martinpinto/696a48a66accff345441 to your computer and use it in GitHub Desktop.
Save martinpinto/696a48a66accff345441 to your computer and use it in GitHub Desktop.
Pinto Sort
function swap(arr, a, b) {
var tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
}
function sort(arr) {
var i = 0;
var isSorting = false;
while (i < arr.length) {
if (i == 0)
isSorting = false;
if (i == arr.length - 1) {
if (!isSorting) break;
i = 0;
}
else if (arr[i + 1] < arr[i]) {
swap(arr, i, i + 1);
isSorting = true;
i++;
} else {
i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment