Created
July 2, 2022 03:46
-
-
Save m-root/ed47e17336aaee8bd9eddf7060eaae2b to your computer and use it in GitHub Desktop.
This is a chain and link array sort for python arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [[6, 1], [1, 2], [3, 4], [5, 6], [2, 3], [4, 5]] | |
def separator(ab, b): | |
if b.index(ab) == 0: | |
return b[1] | |
else: | |
return b[0] | |
import time | |
def pair_sorting(start_item = 1, array_edit = arr): | |
new_arr = [] | |
time_start = time.time() | |
print(time_start) | |
while len(array_edit) > 0: | |
for aa in array_edit: | |
if start_item not in aa: | |
aa = [b for b in array_edit if start_item in b][0] | |
print(aa) | |
ans = separator(start_item, aa) | |
print(ans) | |
array_edit.remove(aa) | |
start_item = ans | |
new_arr.append(aa) | |
print(time.time()-time_start) | |
print(new_arr) | |
return new_arr | |
pair_sorting() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment