Skip to content

Commit 6f02d24

Browse files
Create permutationSort.m
1 parent e051eac commit 6f02d24

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function list = permutationSort(list)
2+
3+
permutations = perms(1:numel(list)); %Generate all permutations of the item indicies
4+
5+
%Test every permutation of the indicies of the original list
6+
for i = (1:size(permutations,1))
7+
if issorted( list(permutations(i,:)) )
8+
list = list(permutations(i,:));
9+
return %Once the correct permutation of the original list is found break out of the program
10+
end
11+
end
12+
13+
end

0 commit comments

Comments
 (0)