MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / Partition

Function Partition

Data-Structures/Array/QuickSelect.js:40–54  ·  view source on GitHub ↗
(items, left, right)

Source from the content-addressed store, hash-verified

38}
39
40function Partition(items, left, right) {
41 const x = items[right]
42 let pivotIndex = left - 1
43
44 for (let j = left; j < right; j++) {
45 if (items[j] <= x) {
46 pivotIndex++
47 Swap(items, pivotIndex, j)
48 }
49 }
50
51 Swap(items, pivotIndex + 1, right)
52
53 return pivotIndex + 1
54}
55
56function getRandomInt(min, max) {
57 return Math.floor(Math.random() * (max - min + 1)) + min

Callers 1

RandomizedPartitionFunction · 0.85

Calls 1

SwapFunction · 0.85

Tested by

no test coverage detected