Difference between revisions 372222 and 373668 on plwikisource{{Nagłówek |tytuł=Sortowanie bąbelkowe |sekcja=Kod źródłowy |adnotacje={{Wikipedia|strona=Sortowanie bąbelkowe|dopełniacz=Sortowanie bąbelkowe}} }} {{Spis treści}} ==BASH== * <tt>$lz</tt> - ilość liczb do posortowania * <tt>$tab[]</tt> - tablica elementów ciągu * <tt>$tmp</tt> - zmienna pomocnicza <source lang="bash"> for(( i=1 ; $i < $lz ; i++ )) ; do for(( j=$(($lz-1)) ; $j >= $i ; j-- )); do if [ ${tab[j-1]} -gt ${tab[j]} ]; then tmp=${tab[j-1]} tab[j-1]=${tab[j]} tab[j]=$tmp fi done done </source> ==C== Wersja klasyczna: <source lang="C"> void bubblesort(int table[], int size) { int i, j, temp; for (i = 0; i<size; i++) {⏎ for (j=0; j<size-1-i; j++) { if (table[j] > table[j+1]) { temp = table[j+1]; table[j+1] = table[j]; table[j] = temp; } } } </source> Wersja z zapamiętaniem czy dokonano zamiany: * <tt>tab[]</tt> - tablica elementów ciągu np. o indeksach od 0 do 99 * <tt>tmp</tt> - zmienna pomocnicza o formacie elementu tablicy <tt>tab[]</tt> * <tt>change</tt> - zmienna logiczna (contracted; show full) for (int i = 0, size = a.length - 1; i < a.length - 1; i++, size--) { for (int j = 0; j < size; j++) for (int temp = a[j]; a[j] > a[j + 1]; a[j] = a[j + 1], a[j + 1] = temp) ; } } </source> [[Kategoria:Kody źródłowe]] All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://pl.wikisource.org/w/index.php?diff=prev&oldid=373668.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|