Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def CycleSort(MyArray):
- Writes = 0
- for cycleStart in range(0, len(MyArray) - 1):
- Item = MyArray[cycleStart]
- Position = cycleStart
- for i in range(cycleStart + 1, len(MyArray)):
- if MyArray[i] < Item:
- Position += 1
- if Position == cycleStart:
- continue
- while Item == MyArray[Position]:
- Position += 1
- MyArray[Position], Item = Item, MyArray[Position]
- Writes += 1
- while Position != cycleStart:
- Position = cycleStart
- for i in range(cycleStart + 1, len(MyArray)):
- if MyArray[i] < Item:
- Position += 1
- while Item == MyArray[Position]:
- Position += 1
- MyArray[Position], Item = Item, MyArray[Position]
- Writes += 1
- return MyArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement