Skip to content

Instantly share code, notes, and snippets.

@winsonwq
Created January 3, 2012 08:21
Show Gist options
  • Select an option

  • Save winsonwq/1554056 to your computer and use it in GitHub Desktop.

Select an option

Save winsonwq/1554056 to your computer and use it in GitHub Desktop.
BubbleSort of Mr.Async.Interpreter
// 算法本身
for(var i = 0 ; i < arr.length - 1 ; i++){
for(var ii = i + 1; ii < arr.length ; ii++){
if(arr[i] > arr[ii])
normalSwap(arr, i, ii);
}
}
// 利用了Mr.Async.Interpreter的方式
eval(Mr.Async.recode(function(){
for(var i = 0 ; i < arr.length - 1 ; i++){
for(var ii = i + 1; ii < arr.length ; ii++){
if(arr[i] > arr[ii])
$await(asyncSwap(arr, i, ii));
}
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment