Skip to content

Commit ee6c4ad

Browse files
authored
Create gnome_sort.m
Sorting Algorithm
1 parent e7180a1 commit ee6c4ad

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

algorithms/sorting/gnome_sort.m

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function list = gnomeSort(list)
2+
3+
i = 2;
4+
j = 3;
5+
6+
while i <= numel(list)
7+
8+
if list(i-1) <= list(i)
9+
i = j;
10+
j = j+1;
11+
else
12+
list([i-1 i]) = list([i i-1]); %Swaping
13+
i = i-1;
14+
if i == 1
15+
i = j;
16+
j = j+1;
17+
end
18+
end %if
19+
20+
end %while
21+
end %gnomeSort

0 commit comments

Comments
 (0)