您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Implements the QuickSort algorithm in Python
- // ==UserScript==
- // @name QuickSort Algorithm
- // @description Implements the QuickSort algorithm in Python
- // @match *://*/*
- // @version 0.0.1.20240417150038
- // @namespace https://greasyfork.org/users/1289520
- // ==/UserScript==
- function quicksort(arr) {
- if (arr.length <= 1) {
- return arr;
- }
- const pivot = arr[Math.floor(arr.length / 2)];
- const left = [];
- const middle = [];
- const right = [];
- arr.forEach(element => {
- if (element < pivot) {
- left.push(element);
- } else if (element > pivot) {
- right.push(element);
- } else {
- middle.push(element);
- }
- });
- return quicksort(left).concat(middle, quicksort(right));
- }
- // Example usage:
- const arr = [3, 6, 8, 10, 1, 2, 1];
- console.log(quicksort(arr));