b'\n_START_ARTICLE_\nGreitojo rikiavimo algoritmas\n_START_SECTION_\nSud\xc4\x97tingumas\n_START_PARAGRAPH_\nGreito rikiavimo algoritmas geriausiai veikia, kai kiekvien\xc4\x85kart slenkstis skaido duomenis po lygiai. \xc5\xa0iuo atveju algoritmo sud\xc4\x97tingumas yra O(N\xc2\xa0 log\xc2\xa0N), lyginimo operacij\xc5\xb3 naudojama 2N\xc2\xa0 log\xe2\x82\x82N. Ta\xc4\x8diau esant \xe2\x80\x9eblogiems\xe2\x80\x9c duomenims, algoritmo sud\xc4\x97tingumas gali siekti O(N\xc2\xb2), d\xc4\x97l to siekiant nusp\xc4\x97jamo rezultato, \xc5\xa1is algoritmas derinamas su kitais.\n_START_SECTION_\nRealizacija C kalba\n_START_PARAGRAPH_\nvoid swap(int a, int b) {_NEWLINE_  int t = list[a];_NEWLINE_  list[a] = list[b];_NEWLINE_  list[b] = t;}int partition(int a, int b, int piv) {_NEWLINE_  int store, i;_NEWLINE_  int piv_value = list[piv];_NEWLINE_   _NEWLINE_  store = a;_NEWLINE_  swap(piv, b);_NEWLINE_  for (i = a; i < b; i++) {_NEWLINE_    if (list[i] < piv_value) {_NEWLINE_      swap(i, store);_NEWLINE_      store++;_NEWLINE_    }_NEWLINE_  }_NEWLINE_  swap(store, b);_NEWLINE_  return store;}_NEWLINE_ _NEWLINE_void sort(int a, int b) {_NEWLINE_  int piv;_NEWLINE__NEWLINE_  if (a < b) {_NEWLINE_    piv = partition(a, b, (a+b)/2);_NEWLINE_    sort(a, piv-1);_NEWLINE_    sort(piv+1, b);_NEWLINE_  }}\n_START_SECTION_\nRealizacija C++ kalba\n_START_PARAGRAPH_\n#include <functional>#include <algorithm>#include <iterator>template< typename BidirectionalIterator, typename Compare >void quick_sort( BidirectionalIterator first, BidirectionalIterator last, Compare cmp ) {_NEWLINE_  if( first != last ) {_NEWLINE_    BidirectionalIterator left  = first;_NEWLINE_    BidirectionalIterator right = last;_NEWLINE_    BidirectionalIterator pivot = left++;_NEWLINE__NEWLINE_    while( left != right ) {_NEWLINE_      if( cmp( *left, *pivot ) ) {_NEWLINE_         ++left;_NEWLINE_      } else {_NEWLINE_         while( (left != --right) && cmp( *pivot, *right ) )_NEWLINE_           ;_NEWLINE_         std::iter_swap( left, right );_NEWLINE_      }_NEWLINE_    }_NEWLINE__NEWLINE_    --left;_NEWLINE_    std::iter_swap( first, left );_NEWLINE__NEWLINE_    quick_sort( first, left, cmp );_NEWLINE_    quick_sort( right, last, cmp );_NEWLINE_  }}template< typename BidirectionalIterator >inline void quick_sort( BidirectionalIterator first, BidirectionalIterator last ) {_NEWLINE_  quick_sort( first, last,_NEWLINE_    std::less_equal< typename std::iterator_traits< BidirectionalIterator >::value_type >()_NEWLINE_  );}\n_START_SECTION_\nRealizacija Java kalba\n_START_PARAGRAPH_\nimport java.util.Random;public class Pavyzdys {_NEWLINE_   private static final Random rand = new Random();_NEWLINE_   ...._NEWLINE__NEWLINE_   public static void keisti(int[] masyvas, int pirmas, int antras) {_NEWLINE_       if (pirmas != antras) {_NEWLINE_           masyvas[antras] -= masyvas[pirmas];_NEWLINE_           masyvas[pirmas] += masyvas[antras];_NEWLINE_           masyvas[antras] *= -1;_NEWLINE_           masyvas[antras] += masyvas[pirmas];_NEWLINE_       }_NEWLINE_   }_NEWLINE_   _NEWLINE_   public static int dalinti(int[] masyvas, int kaire, int desine) {_NEWLINE_       int t = kaire + rand.nextInt(desine - kaire + 1);_NEWLINE_       keisti(masyvas, t, kaire);_NEWLINE_       int indeksas = kaire;_NEWLINE_       for (int j = kaire + 1; j <= desine; ++j) {_NEWLINE_           if (masyvas[j] < masyvas[kaire]) {_NEWLINE_               ++indeksas;_NEWLINE_               keisti(masyvas, indeksas, j);                            _NEWLINE_           }_NEWLINE_       }_NEWLINE_       keisti(masyvas, kaire, indeksas);_NEWLINE_       return indeksas;_NEWLINE_   }_NEWLINE_   _NEWLINE_   public static void rusiuoti(int[] masyvas, int kaire, int desine) {_NEWLINE_       if (kaire < desine) {_NEWLINE_           int indeksas = dalinti(masyvas, kaire, desine);_NEWLINE_           rusiuoti(masyvas, kaire, indeksas - 1);_NEWLINE_           rusiuoti(masyvas, indeksas + 1, desine);_NEWLINE_       }_NEWLINE_   }_NEWLINE_   _NEWLINE_   ...}\n_START_SECTION_\nRealizacija Perl kalba\n_START_PARAGRAPH_\n@masyvas = ( -1, 0, 7, 8, 6, 9, 5, 2, 2, -3, 4, 6, 8, 9, -2 );rusiuoti( 0, $#masyvas );print "Rezultatas: @masyvas";sub keisti {_NEWLINE_    ( $_[0], $_[1] ) = ( $_[1], $_[0] );}sub dalinti {_NEWLINE_    my ($kaire, $desine, $t, $indeksas) = ($_[0], $_[1], $_[0], $_[0]);_NEWLINE_    for ( $j = $kaire + 1 ; $j <= $desine ; ++$j ) {_NEWLINE_        if ( $masyvas[$j] < $masyvas[$kaire] ) {_NEWLINE_            ++$indeksas;_NEWLINE_            keisti( $masyvas[$indeksas], $masyvas[$j] );_NEWLINE_        }_NEWLINE_    }_NEWLINE_    keisti( $masyvas[$kaire], $masyvas[$indeksas] );_NEWLINE_    return $indeksas;}sub rusiuoti {_NEWLINE_    my ( $kaire, $desine ) = ( $_[0], $_[1] );_NEWLINE_    if ( $kaire < $desine ) {_NEWLINE_        my ($indeksas) = dalinti( $kaire, $desine );_NEWLINE_        rusiuoti( $kaire, $indeksas \xe2\x80\x93 1 );_NEWLINE_        rusiuoti( $indeksas + 1, $desine );_NEWLINE_    }}\n_START_SECTION_\nRealizacija Python kalba\n_START_PARAGRAPH_\ndef dalinti ( kaire, desine ):_NEWLINE_    t = indeksas = kaire;_NEWLINE_    for j in range( kaire + 1, desine + 1 ):_NEWLINE_        if masyvas[j] < masyvas[kaire]:_NEWLINE_            indeksas += 1;_NEWLINE_            masyvas[indeksas], masyvas[j] = masyvas[j], masyvas[indeksas]_NEWLINE_    masyvas[kaire], masyvas[indeksas] = masyvas[indeksas], masyvas[kaire]_NEWLINE_    return indeksas;def rusiuoti( kaire, desine ):_NEWLINE_    if kaire < desine :_NEWLINE_        indeksas = dalinti( kaire, desine )_NEWLINE_        rusiuoti( kaire, indeksas - 1)_NEWLINE_        rusiuoti( indeksas + 1, desine )_NEWLINE_    _NEWLINE_masyvas = [ -1, 0, 7, 8, 6, 9, 5, 2, 2, -3, 4, 6, 8, 9, -2 ]rusiuoti ( 0, len( masyvas ) - 1 )print ("Rezultatas: ", masyvas)'