<pre class="plain" name="code">#!bin/bash
#选择排序
values=(39 5 36 12 9 3 2 30 4 18 22 1 28 25)
numvalues=${#values[@]}
for (( i=0; i < numvalues; i++ )); do
lowest=$i
for (( j=i+1; j < numvalues; j++ )); do
if [ ${values[j]} -le ${values[$lowest]} ]; then
lowest=$j
fi
done
temp=${values[i]}
values[i]=${values[lowest]}
values[lowest]=$temp
done
echo ${values[*]}
#冒泡排序
li=(1 4 2 7 9 5 6 3 8 0)
num=${#li[@]}
for (( i=0; i<num; i++)); do
for (( j=i+1; j<num; j++ )); do
if [ ${li[i]} -gt ${li[j]} ]; then
temp=${li[j]}
li[j]=${li[i]}
li[i]=$temp
fi
done
done
echo ${li[*]}