Skip to content
Merged
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
26 changes: 26 additions & 0 deletions algorithms/sorting/shell_sort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function list = shellSort(list)

N = numel(list);
increment = round(N/2);

while increment > 0 %loop until increment becomes 0

for i = (increment+1:N)
temp = list(i);
j = i;
while (j >= increment+1) && (list(j-increment) > temp)
list(j) = list(j-increment);
j = j - increment;
end

list(j) = temp;

end %for

if increment == 2 %This case causes shell sort to become insertion sort
increment = 1;
else
increment = round(increment/2.2);
end
end %while
end %shellSort