Created
August 18, 2012 16:20
-
-
Save JeffreyZhao/3388096 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
var bubbleSort = function (array, _) { | |
for (var i = 0; i < array.length; i++) { | |
for (var j = 0; j < array.length - i - 1; j++) { | |
var r = compareAsync(array[j], array[j + 1], _); | |
if (r > 0) swapAsync(array, j, j + 1, _); | |
} | |
} | |
} |
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
var bubbleSort = function bubbleSort__1(array, _) { | |
var i, j, r; | |
var __frame = { | |
name: "bubbleSort__1", | |
line: 1 | |
}; | |
return __func(_, this, arguments, bubbleSort__1, 1, __frame, function __$bubbleSort__1() { | |
i = 0; | |
var __3 = false; | |
return (function ___(__break) { | |
var __more; | |
var __loop = __cb(_, __frame, 0, 0, function __$bubbleSort__1() { | |
__more = false; | |
if (__3) { | |
i++; | |
} | |
else { | |
__3 = true; | |
} | |
; | |
var __2 = (i < array.length); | |
if (__2) { | |
j = 0; | |
var __5 = false; | |
return (function ___(__break) { | |
var __more; | |
var __loop = __cb(_, __frame, 0, 0, function __$bubbleSort__1() { | |
__more = false; | |
if (__5) { | |
j++; | |
} | |
else { | |
__5 = true; | |
} | |
; | |
var __4 = (j < ((array.length - i) - 1)); | |
if (__4) { | |
return compareAsync(array[j], array[(j + 1)], __cb(_, __frame, 3, 20, function ___(__0, __1) { | |
r = __1; | |
return (function __$bubbleSort__1(__then) { | |
if ((r > 0)) { | |
return swapAsync(array, j, (j + 1), __cb(_, __frame, 4, 23, __then, true)); | |
} | |
else { | |
__then(); | |
} | |
; | |
})(function __$bubbleSort__1() { | |
while (__more) { | |
__loop(); | |
}; | |
__more = true; | |
}); | |
}, true)); | |
} | |
else { | |
__break(); | |
} | |
; | |
}); | |
do { | |
__loop(); | |
} while (__more); | |
__more = true; | |
})(function __$bubbleSort__1() { | |
while (__more) { | |
__loop(); | |
}; | |
__more = true; | |
}); | |
} | |
else { | |
__break(); | |
} | |
; | |
}); | |
do { | |
__loop(); | |
} while (__more); | |
__more = true; | |
})(_); | |
}); | |
}; |
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
var bubbleSortAsync = eval(Wind.compile("async", function (array) { | |
for (var i = 0; i < array.length; i++) { | |
for (var j = 0; j < array.length - i - 1; j++) { | |
var r = $await(compareAsync(array[j], array[j + 1])); | |
if (r > 0) $await(swapAsync(array, j, j + 1)); | |
} | |
} | |
})); |
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
/* async << function (array) { */ (function (array) { | |
var _builder_$0 = Wind.builders["async"]; | |
return _builder_$0.Start(this, | |
_builder_$0.Delay(function () { | |
/* var i = 0; */ var i = 0; | |
/* for ( */ return _builder_$0.For(function () { | |
/* ; i < array.length */ return i < array.length; | |
}, function () { | |
/* ; i ++) { */ i ++; | |
}, | |
_builder_$0.Delay(function () { | |
/* var j = 0; */ var j = 0; | |
/* for ( */ return _builder_$0.For(function () { | |
/* ; j < array.length - i - 1 */ return j < array.length - i - 1; | |
}, function () { | |
/* ; j ++) { */ j ++; | |
}, | |
_builder_$0.Delay(function () { | |
/* var r = $await(compareAsync(array[j], array[j + 1])); */ return _builder_$0.Bind(compareAsync(array[j], array[j + 1]), function (r) { | |
/* if (r > 0) { */ if (r > 0) { | |
/* $await(swapAsync(array, j, j + 1)); */ return _builder_$0.Bind(swapAsync(array, j, j + 1), function () { | |
return _builder_$0.Normal(); | |
}); | |
/* } */ } else { | |
return _builder_$0.Normal(); | |
} | |
}); | |
}) | |
/* } */ ); | |
}) | |
/* } */ ); | |
}) | |
); | |
/* } */ }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment