Created
October 3, 2021 09:38
-
-
Save Cosmicoppai/752b471235dd590dcfe3c16e498267ea to your computer and use it in GitHub Desktop.
Shell Script of Bubble sort
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
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