strCmp(str1,str2)自己写的字符串比较函数

def strCmp(s1,s2):
    aLi = list(s1)
    bLi = list(s2)
    alen = len(s1)
    blen = len(s2)
    if alen > blen:
        lenth = blen
    else:
        lenth = alen
    for x in range(lenth):
        if aLi[0] == bLi[0]:
            aLi.pop(0);bLi.pop(0)
            if len(aLi) != 0 and len(bLi) != 0:
                continue
            elif len(aLi)== 0 and len(bLi) == 0:
                return 0
                break
            elif len(aLi) == 0:
                return -1
                break
            elif len(bLi) == 0:
                return 1
                break
            
        elif aLi[0] > bLi[0]:
            return 1
            break
        elif aLi[0] < bLi[0]:
            return -1
            break
str1 = raw_input('Enter the first string:')
str2 = raw_input('Enter the second string:')
print 'The compare result is:',
print strCmp(str1,str2)

 

posted @ 2015-03-25 09:51  &苍云  阅读(513)  评论(0编辑  收藏  举报