Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BubbleSort {
- private Sorter (arrayList, order) {
- var temp;
- for (var i = 0; i < arrayList.length - 1; i++) {
- for (var j = i; j < arrayList.length - i; j++) {
- if ((order == 'asc' ? (arrayList[j-1] > arrayList[j]) : (arrayList[j-1] < arrayList[j]))) {
- temp = arrayList[j-1];
- arrayList[j-1] = arrayList[j];
- arrayList[j] = temp;
- }
- }
- }
- }
- Ascending (arrayList) {
- if (!arrayList.length) {
- return;
- }
- Sorter(arraylist, 'asc');
- }
- Descending (arrayList) {
- if (!arrayList.length) {
- return;
- }
- Sorter(arraylist, 'desc');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement