Shell script programming (quick sorting)
[Cpp] view plaincopy
- #! /Bin/bash
- # Implementation of fast sorting in shell script programming (using the rightmost element as the element)
- A = (851032934123409618629)
- # A = (00001233448283049592143716)
- Temp =
- Buff =
- # Switching functions
- Swap ()
- {
- Buff =$ {a [$1]}
- A [$1] =$ {a [$2]}
- A [$2] = $ buff
- }
- Fun ()
- {
- I = $($1-1 ))
- J = $1
- Temp =$ {a [$2]}
- Iftest $ 1-ge $2; then
- Return2
- Fi
- While [$ j-le $2]; do
- [$ J-lt $2] & while [[$ {a [$ j]}-gt $ temp]; do
- J = $ ($ j + 1 ))
- Done
- I = $ ($ I + 1 ))
- Swap $ I $ j
- J = $ ($ j + 1 ))
- Done
- Fun0 $ ($ i-1 ))
- Fun $ ($ I + 2) $2
- }
- Fun015
- For (I = 0; I <16; I ++ ))
- {
- Echo-n $ {a [$ I]} ""
- }
- Echo
- Exit0
The following is the comparison code of C ++ quick sorting.
[Cpp] view plaincopy
- # Include <iostream>
- Usingnamespacestd;
- Voidswap (int * a, int * B)
- {
- Inttemp = *;
- * A = * B;
- * B = temp;
- }
- VoidGrial (inta [], intx, inty)
- {
- Inti = X-1;
- Intj = x;
- If (x> = y) return;
- Inttemp = 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 );
- }
- Intmain ()
- {
- Inta [] = };
- Grial (a, 0, 14 );
- For (inti = 0; I <15; I ++)
- {
- Cout <a [I] <"";
- }
- Cout <endl;
- }