Skip to content

Commit

Permalink
feat: menambahkan contoh sederhana bubble sorting (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: slowy07 <slowy.arfy@proton.me>
  • Loading branch information
slowy07 authored Sep 29, 2024
1 parent b0eb819 commit aa36883
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions simple_project/sorting/bubble_sorting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

array=(5 2 1 7 3 9)

# menampilkan array yang tidak tersorting
echo "array yang tidak tersorting:"
echo ${array[*]}

for ((i = 0; i<${#array[@]}; i++))
do

for((j = i; j<${#array[@]}-i-1; j++))
do

if ((${array[j]} > ${array[$((j+1))]}))
then
temp=${array[$j]}
array[$j]=${array[$((j+1))]}
array[$((j+1))]=$temp
fi
done
done

echo "array yang telah di sorting:"
echo ${array[*]}

0 comments on commit aa36883

Please sign in to comment.