Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
function list = combSort(list)
|
||||
|
||||
listSize = numel(list);
|
||||
gap = int32(listSize); %Coerce gap to an int so we can use the idivide function
|
||||
swaps = true; %Swap flag
|
||||
|
||||
while not((gap <= 1) && (swaps == false))
|
||||
|
||||
gap = idivide(gap,1.25,'floor'); %Int divide, floor the resulting operation
|
||||
|
||||
if gap < 1
|
||||
gap = 1;
|
||||
end
|
||||
|
||||
i = 1; %i equals 1 because all arrays are 1 based in MATLAB
|
||||
swaps = false;
|
||||
|
||||
%i + gap must be subtracted by 1 because the pseudo-code was writen
|
||||
%for 0 based arrays
|
||||
while not((i + gap - 1) >= listSize)
|
||||
|
||||
if (list(i) > list(i+gap))
|
||||
list([i i+gap]) = list([i+gap i]); %swap
|
||||
swaps = true;
|
||||
end
|
||||
i = i + 1;
|
||||
|
||||
end %while
|
||||
end %while
|
||||
end %combSort
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
>> combSort([4 3 1 5 6 2])
|
||||
|
||||
ans =
|
||||
|
||||
1 2 3 4 5 6
|
||||
Loading…
Add table
Add a link
Reference in a new issue