Dutch national flag problem: Difference between revisions

→‎{{header|M2000 Interpreter}}: Added Three Way Partition method
(→‎{{header|M2000 Interpreter}}: Added Three Way Partition method)
Line 2,137:
 
=={{header|M2000 Interpreter}}==
Most times the Three Way Partition makes more changed than the first algorithm. Also if the array is sorted from the start, no changes give the first algorithm and 23 changes the Three Way Partition,
 
<lang M2000 Interpreter>
Line 2,273 ⟶ 2,274:
Report TestSort$(final())+Display$(final())
print "changes: "; many
Module three_way_partition (A as array, mid as balls, &swaps) {
Def i, j, k
k=Len(A)
Link A to A()
While j < k
if A(j) < mid Then
Swap A(i), A(j)
swaps++
i++
j++
Else.if A(j) > mid Then
k--
Swap A(j), A(k)
swaps++
Else
j++
End if
End While
}
Many=0
Z=second()
Print
Report center, {Three Way Partition
}
Report TestSort$(Z)+Display$(Z)
three_way_partition Z, White, &many
Print
Report TestSort$(Z)+Display$(Z)
Print "changes: "; many
 
</lang>
 
Line 2,286 ⟶ 2,317:
sorted: Red, Red, Red, Red, Red, Red, Red, Red, Red, White, White, White, White, White, White, White, White, White, White, White, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue
changes: 20
Three Way Partition
unsorted: Red, White, White, Red, Red, White, Blue, Red, Red, Blue, Red, Blue, White, White, Red, White, Blue, Blue, White, Blue, Red, Blue, Blue, White, Blue, White, Blue, Red, White, White
sorted: Red, Red, Red, Red, Red, Red, Red, Red, Red, White, White, White, White, White, White, White, White, White, White, White, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue
changes: 19
</pre>
 
404

edits