← RETURN_TO_CORE
熵减与排序
PROTOCOL: ENTROPY_REDUCTION | AVG_O: O(n log n)
LIVE_VISUALIZATION
[ MODULE_VISUALIZER_LOADING ]
SOURCE_CODE // DECRYPTED
混沌数据的熵减过程 // 快速排序。通过严密的交换规则重组无序状态,建立绝对秩序。
quick_sort.tsREAD_ONLY
function quickSort(arr: number[]): number[] {
if (arr.length <= 1) return arr;
// 确立空间基准点 (Pivot)
const pivotIndex = Math.floor(arr.length / 2);
const pivot = arr[pivotIndex];
const left: number[] = [];
const right: number[] = [];
for (let i = 0; i < arr.length; i++) {
if (i === pivotIndex) continue;
// 质量分拣:轻者归左,重者归右
if (arr[i] < pivot) left.push(arr[i]);
else right.push(arr[i]);
}
// 递归闭环与宇宙重组
return [...quickSort(left), pivot, ...quickSort(right)];
}