The following Python codes gives all possible sort result of a list:
def mysort(data):
if len(data) == 1:
return [data]
res = []
tail = data.pop()
all_sort = mysort(data)
for one_sort in all_sort:
for i in range(0,len(one_sort)):
res.append(one_sort[:i] + [tail] + one_sort[i:])
return res
aa = [1, 2, 3, 4, 5]
print(mysort(aa))