Shell script programming (Quick Sort)

Source: Internet
Author: User

#!/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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.