展开全部
一、直接搜索e68a84e8a2ad62616964757a686964616f31333337626163def find(s, sub):
ls = len(s)
lsub = len(sub)
for i in range(ls-lsub+1):
if s[i:i+lsub]==sub:
return i
return -1
s = 'ABCDEFG'
sub = 'DE'
print(find(s,sub))
二、qsort快速排序def comp(a,b):
if a > b:
return True
else:
return False
def quickSort(L, low, high, comp):
i = low
j = high
if i >= j:
return L
key = L[i]
while i < j:
while i < j and comp(L[j], key):
j = j-1
L[i] = L[j]
while i < j and comp(key, L[i]):
i = i+1
L[j] = L[i]
L[i] = key
quickSort(L, low, i-1, comp)
quickSort(L, j+1, high,comp)
return L
def qsort(L, comp):
return quickSort(L, 0, len(L)-1, comp)
L = [3,4,5,1,2]
#print(comp(1,2))
print(qsort(L,comp))