Created
January 29, 2015 16:52
-
-
Save copy/8ef2af76f636fa648c72 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
function swap(arr, i, j) | |
{ | |
var t = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = t; | |
} | |
function sorty(arr) | |
{ | |
var end = arr.length - 1; | |
var start = 0; | |
while(start < end) | |
{ | |
if(arr[start] >= 0) | |
{ | |
while(start < end && arr[end] >= 0) | |
{ | |
end--; | |
} | |
if(start < end) | |
{ | |
swap(arr, start, end); | |
} | |
} | |
if(start < end) | |
{ | |
start++; | |
} | |
} | |
end = arr.length - 1; | |
while(start < end) | |
{ | |
if(arr[start] > 0) | |
{ | |
while(start < end && arr[end] > 0) | |
{ | |
end--; | |
} | |
if(start < end) | |
{ | |
swap(arr, start, end); | |
} | |
} | |
if(start < end) | |
{ | |
start++; | |
} | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi