An example Blockly bubble sort is here:
https://blockly-demo.appspot.com/static/demos/code/index.html#bfen2c
Screenshot:
Generated Python source code:
import random
List = None
I = None
J = None
Left = None
Right = None
List = [random.randint(1,100),random.randint(1,100),random.randint(1,100)]
I = 1
while I < len(List):
J = I + 1
while J <= len(List):
Left = List[int(I - 1)]
Right = List[int(J - 1)]
if Left > Right:
List[int(I - 1)] = Right
List[int(J - 1)] = Left
J = J + 1
#End J
I = I + 1
#End I
print(List[0])
print(List[1])
print(List[2])
No comments:
Post a Comment