Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions cycle_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

from OFA import *

def sort(list = blocks):
for b in list:
print(b.h, end = " ")
print()
writes = 0
LS = len(list)

for i in range(LS-1):
item = list[i]
pos = i
for j in range(i + 1, LS):
if list[j].h < item.h:
pos += 1
if pos == i:
continue

while item == list[pos]:
pos += 1


swap(pos, i, list)
writes += 1


while pos != i:

pos = i

for j in range(i + 1, LS):
if list[j].h < item.h:
pos += 1

while item == list[pos]:
pos += 1

# list[pos], item = item, list[pos]
swap(pos, i, list)
writes += 1
for b in list:
print(b.h, end = " ")
print()

if __name__ == "__main__":
tk.title("Cycle Sort")
generate()
btn1 = Button(tk, text='Shuffle', bd='5', command=lambda: shuffle())
btn2 = Button(tk, text='Sort', bd='5', command=lambda: sort())
btn1.pack(side='left')
btn2.pack(side='left')
tk.mainloop()

7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from cocktail_sort import sort as CS

from cycle_sort import sort as CyS


from OFA import *


Expand Down Expand Up @@ -43,6 +46,8 @@

btn9 = Button(tk, text = 'Cocktail Sort', bd = '5', command = lambda: CS())

btnnizam = Button(tk, text = 'Cycle Sort', bd = '5', command = lambda: CyS())

btn1.place(x = 710, y = 5)

btn2.place(x = 710, y = 65)
Expand All @@ -61,4 +66,6 @@

btn9.place(x = 710, y = 275)

btnnizam.place(x = 710, y = 305)

tk.mainloop()