#!/bin/bash#shell implementation of the fast sequencing of script programming (with the idea of a meta-point at the far right) a= (8 5 3 2 for 4 1 2 3-9, 8 6) #a = (0 0 0 0 1 2 3 3 4 4 8 30495 921 43716) temp=buff= #交换函数swap () {buff=${a[$1]}a[$1]=${a[$ 2]}a[$2]= $buff}fun () {i=$ ($1-1) j=$1temp=${a[$2]}if test $1-ge; Thenreturn 2 Fiwhile [$j-le $];d o[$j-lt $] &am p;& while [[${a[$j]}-gt $temp]];d o j=$ (($j + 1)) donei=$ (($i + 1)) Swap $i $jj =$ (($j + 1)) did fun 0 $ (($i-1)) Fun $ (($i +2 )) $2}fun 0 15for ((i=0;i<16;i++)) {echo-n ${a[$i]} ""}echoexit 0
Here is a comparison code for C + + Quick sort
#include <iostream>using namespace std;void swap (int *a,int *b) {int temp = *a;*a = *b;*b = temp;} void grial (int a[],int x,int y) {int i=x-1;int j=x;if (x>=y) Return;int temp = A[y];while (j<=y) {while (j<y& &a[j]>a[y]) J++;i++;swap (&a[i],&a[j]); j + +;} Grial (a,0,i-1); Grial (a,i+1,y);} int main () {int a[]={4,3,921,30495,28,43716,3,4,0,0,2,0,0,1,8,5}; Grial (a,0,14); for (int i=0;i<15;i++) {cout<<a[i]<< " ";} Cout<<endl;}
Shell script programming (Quick Sort)