all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,28 @@
function list = pancakeSort(list)
for i = (numel(list):-1:2)
minElem = list(i);
minIndex = i;
%Find the min element in the current subset of the list
for j = (i:-1:1)
if list(j) <= minElem
minElem = list(j);
minIndex = j;
end
end
%If the element is already in the correct position don't flip
if i ~= minIndex
%First flip flips the min element in the stack to the top
list(minIndex:-1:1) = list(1:minIndex);
%Second flip flips the min element into the correct position in
%the stack
list(i:-1:1) = list(1:i);
end
end %for
end %pancakeSort

View file

@ -0,0 +1,5 @@
>> pancakeSort([4 3 1 5 6 2])
ans =
6 5 4 3 2 1