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 = cocktailSort(list)
|
||||
|
||||
%We have to do this because the do...while loop doesn't exist in MATLAB
|
||||
swapped = true;
|
||||
|
||||
while swapped
|
||||
|
||||
%Bubble sort down the list
|
||||
swapped = false;
|
||||
for i = (1:numel(list)-1)
|
||||
if( list(i) > list(i+1) )
|
||||
list([i i+1]) = list([i+1 i]); %swap
|
||||
swapped = true;
|
||||
end
|
||||
end
|
||||
|
||||
if ~swapped
|
||||
break
|
||||
end
|
||||
|
||||
%Bubble sort up the list
|
||||
swapped = false;
|
||||
for i = (numel(list)-1:-1:1)
|
||||
if( list(i) > list(i+1) )
|
||||
list([i i+1]) = list([i+1 i]); %swap
|
||||
swapped = true;
|
||||
end %if
|
||||
end %for
|
||||
end %while
|
||||
end %cocktail sort
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
cocktailSort([6 3 7 8 5 1 2 4 9])
|
||||
|
||||
ans =
|
||||
|
||||
1 2 3 4 5 6 7 8 9
|
||||
Loading…
Add table
Add a link
Reference in a new issue