len2 = len(str2)
i = 0
j = 0
while i < len1 and j < len2:
if list(str1)[i] not in char_to_int.keys():
char_to_int[list(str1)[i]] = -1
if list(str2)[i] not in char_to_int.keys():
char_to_int[list(str2)[j]] = -1
# 比较各个字符的大小
if char_to_int[list(str1)[i]] < char_to_int[list(str2)[j]]:
return - 1
elif char_to_int[list(str1)[i]] > char_to_int[list(str2)[j]]:
return 1
else:
i += 1
j += 1
if i == len1 and j == len2:
return 0
elif i == len1:
return -1
else:
return 1
def insertSort(s, char_to_int):
lens = len(s)
i = 1
while i < lens:
temp = s[i]
j = i - 1
while j >= 0:
if compare(temp, s[j], char_to_int) == -1:
s[j + 1] = s[j]
else:
break
j -= 1
s[j + 1] = temp
i += 1