如何将步骤/过程(传递#)包含到Python解释器的quicksort代码中

时间:2019-05-08 10:02:46

标签: python quicksort

我尝试加入通行证#,但似乎无法正常运行。

这是我12年级软件设计和开发重大项目的一部分。

此功能(def)用于Quicksort,

显示我的列表以测试代码。

def quicksort(Item):
    used=0
    lastindex= len(Item)-1
    print(Item)
    counter=0
    less = []
    equal = []
    greater = []
    while lastindex>0:
        counter=0
        while counter<lastindex:
            if len(Item) > 1:
                #pivot = Item[0]
                #Testing
                pivot = Item[counter]
                for x in Item:
                    if x < pivot:
                        less.append(x)
                    elif x == pivot:
                        equal.append(x)
                    elif x > pivot:
                        greater.append(x)
                used +=1
                print(Item)
                return quicksort(less)+equal+quicksort(greater)
            counter +=1
            print(Item)
        print("Pass #", len(Item) - lastindex)
        lastindex=lastindex-1
    return(Item)
#            else:
#                return(Item)
#mylist = ["Goose","Yak","Ant","Dog","Moose","Cow","Hen","Rat","Frog","Beetle"]
#print(quicksort(mylist))

0 个答案:

没有答案