Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
type PermutationSort
|
||||
fun isSorted = logic by List a
|
||||
for int i = 1; i < a.length; ++i
|
||||
if a[i - 1] > a[i] do return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
fun permute = void by List a, int n, List lists
|
||||
if n == 1
|
||||
List b = int[]
|
||||
for int i = 0; i < a.length; ++i
|
||||
b.append(a[i])
|
||||
end
|
||||
lists.append(b)
|
||||
return
|
||||
end
|
||||
int i = 0
|
||||
while i < n
|
||||
a.swap(i, n - 1)
|
||||
permute(a, n - 1, lists)
|
||||
a.swap(i, n - 1)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
fun sort = List by List a
|
||||
List lists = List[]
|
||||
permute(a, a.length, lists)
|
||||
for each List list in lists
|
||||
if isSorted(list) do return list end
|
||||
end
|
||||
return a
|
||||
end
|
||||
type Main
|
||||
List a = int[3,2,1,8,9,4,6]
|
||||
writeLine("Unsorted: " + a)
|
||||
a = PermutationSort.sort(a)
|
||||
writeLine(" Sorted: " + a)
|
||||
Loading…
Add table
Add a link
Reference in a new issue