Skip to content

Commit c758641

Browse files
committed
Basic sorting algorithms
1 parent c76a28a commit c758641

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

.DS_Store

6 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash -u
2+
items=("$@")
3+
len="${#items[@]}"
4+
i=1
5+
while [ $i -lt $len ]; do
6+
key="${items[i]}"
7+
j=$((i-1));
8+
while [ $j -ge 0 ] && [ ${items[j]} -gt $key ]; do
9+
items[$((j+1))]=${items[j]}
10+
j=$((j-1))
11+
done
12+
i=$((i+1))
13+
items[$((j+1))]="${key}"
14+
done
15+
16+
echo "${items[@]}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
items=("$@")
4+
len=${#items[@]}
5+
for (( i=0; i < $((len - 1)); i+=1)); do
6+
min_index=$i
7+
for (( j=i+1; j < len; j+=1)); do
8+
if (( items[j] < items[min_index])); then
9+
min_index=$j
10+
fi
11+
done
12+
13+
temp=${items[i]}
14+
items[$i]=${items[min_index]}
15+
items[min_index]=$temp
16+
done
17+
18+
echo "${items[@]}"

Misc/Sattolos/shell/.main.sh.swp

12 KB
Binary file not shown.

0 commit comments

Comments
 (0)