Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Bubble-Sort/BubbleSort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#run node ./BubbleSort.sh to execute
a=(5 6 3 2 56 23 12 89 1)
n=${#a[@]}
x=1

for (( i=0; $x==1 && i<$n-1; i++ ))
do
x=0
for (( j=0; j<$n-i-1; j++ ))
do
# compare the numbers and swap if required
if [ ${a[$j]} -gt ${a[$j+1]} ]
then
tmp=${a[$j]}
a[$j]=${a[$j+1]}
a[$j+1]=$tmp
x=1
fi
done
done

echo ${a[*]}