Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -1,29 +1,29 @@
|
|||
type PermutationSort
|
||||
fun isSorted = logic by List a
|
||||
for int i = 1; i < a.length; ++i
|
||||
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
|
||||
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
|
||||
int i ← 0
|
||||
while i < n
|
||||
a.swap(i, n - 1)
|
||||
permute(a, n - 1, lists)
|
||||
a.swap(i, n - 1)
|
||||
i = i + 1
|
||||
i ← i + 1
|
||||
end
|
||||
end
|
||||
fun sort = List by List a
|
||||
List lists = List[]
|
||||
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
|
||||
|
|
@ -31,7 +31,7 @@ fun sort = List by List a
|
|||
return a
|
||||
end
|
||||
type Main
|
||||
List a = int[3,2,1,8,9,4,6]
|
||||
List a ← int[3,2,1,8,9,4,6]
|
||||
writeLine("Unsorted: " + a)
|
||||
a = PermutationSort.sort(a)
|
||||
a ← PermutationSort.sort(a)
|
||||
writeLine(" Sorted: " + a)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue