Last active
October 27, 2017 04:31
-
-
Save HelloAlberuni/daa8964cc287341e96f658b618585d6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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