Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function zamien {
- swaper=${tab[$1]}
- tab[$1]=${tab[$1+1]}
- tab[$1+1]=$swaper
- }
- read -p "Podawaj liozby: " -a tab
- read -p "Sortowanie rosnace czy malejace? 1 - rosnace, 2 - malejace: " rosCzyMal
- echo Przed sortowaniem: ${tab[*]}
- export tab
- ilEle=$[${#tab[*]}-1]
- for(( y=0 ; y<ilEle ; y++ ))
- do
- for(( x=0 ; x<$[ilEle-y] ; x++ ))
- do
- if [ $rosCzyMal -eq 1 ]
- then
- if [ ${tab[x]} -gt ${tab[x+1]} ]
- then
- zamien $x
- fi
- elif [ $rosCzyMal -eq 2 ]
- then
- if [ ${tab[x]} -lt ${tab[x+1]} ]
- then
- zamien $x
- fi
- fi
- done
- done
- echo Po sortowaniu: ${tab[*]}
Advertisement
Add Comment
Please, Sign In to add comment