Content-Length: 296294 | pFad | http://github.com/lgope/JavaScript/commit/099355e3f93d6ed961007c4b149e6c0fa0acd8ff

0E Update bubbleSortRecursive.js · lgope/JavaScript@099355e · GitHub
Skip to content

Commit 099355e

Browse files
authored
Update bubbleSortRecursive.js
1 parent 928480b commit 099355e

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

algorithms/bubbleSortRecursive.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,18 @@ function bubbleSort(arr, iteration) {
77

88

99
function bubbleSwap(arr, i, j, n) {
10-
1110
if (j >= n) return;
1211

1312
// swap
1413
if (arr[i] > arr[j]) [arr[i], arr[j]] = [arr[j], arr[i]];
1514

16-
1715
bubbleSwap(arr, i + 1, j + 1, n);
1816
}
1917

20-
21-
function sort(arr) {
22-
const n = arr.length;
23-
24-
if (n <= 1) return;
25-
26-
bubbleSort(arr, n);
27-
28-
}
29-
3018
const arr = [1, 8, 6, 5, 4, 9];
3119

32-
sort(arr);
20+
if (arr.length >= 1) bubbleSort(arr, arr.length)
3321

3422
console.log(arr)
23+
24+
// tc => O(n^2)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/lgope/JavaScript/commit/099355e3f93d6ed961007c4b149e6c0fa0acd8ff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy