Skip to content

Instantly share code, notes, and snippets.

@Cosmicoppai
Created October 3, 2021 09:38
Show Gist options
  • Save Cosmicoppai/752b471235dd590dcfe3c16e498267ea to your computer and use it in GitHub Desktop.
Save Cosmicoppai/752b471235dd590dcfe3c16e498267ea to your computer and use it in GitHub Desktop.
Shell Script of Bubble sort
echo "Enter number of elements"
read k
echo "enter array elements"
for ((i=0; i<k; i++))
do
read a[$i]
done
for ((i=0; i<k; i++))
do
for((j=$i; j<k; j++))
do
if [ ${a[$i]} -gt ${a[$j]} ]
then
temp=${a[$i]}
a[$i]=${a[$j]}
a[$j]=$temp
fi
done
done
echo "Array after sorting: "
for ((i=0; i<k; i++))
do
echo ${a[$i]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment