Skip to content

Instantly share code, notes, and snippets.

@HelloAlberuni
Last active October 27, 2017 04:31
Show Gist options
  • Save HelloAlberuni/daa8964cc287341e96f658b618585d6c to your computer and use it in GitHub Desktop.
Save HelloAlberuni/daa8964cc287341e96f658b618585d6c to your computer and use it in GitHub Desktop.
#i/bin/bash
echo Number of inputs
read n
echo Imput $n numbers
for ((i=0;i<$n;i++))
do
read num[$i]
done
echo Number before sort
for((i=0;i<$n;i++))
do
echo ${num[$i]}
done
#bubble short code
x=`expr $n-1`
for((c=0;c<$x;c++))
do
y=`expr $n - $c - 1`
for((d=0;d<y;d++))
do
z=`expr $d + 1`
if [ ${num[$d]} -gt ${num[$z]} ]; then
swap=${num[$d]}
num[$d]=${num[$z]}
num[$z]=$swap
fi
done
done
echo Number after sort
for((i=0;i<$n;i++))
do
echo ${num[$i]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment