median of three values strategy

前端 未结 8 1624
粉色の甜心
粉色の甜心 2020-11-29 23:08

What is the median of three strategy to select the pivot value in quick sort?

I am reading it on the web, but I couldn\'t figure it out what exactly it is? And also

8条回答
  •  情话喂你
    2020-11-29 23:55

    Think simple... Python example....

    def bigger(a,b): #Find the bigger of two numbers ...
        if a > b:
            return a
        else:
            return b
    
    def biggest(a,b,c): #Find the biggest of three numbers ...
        return bigger(a,bigger(b,c))
    
    def median(a,b,c): #Just dance!
        x = biggest(a,b,c)
        if x == a:
            return bigger(b,c)
        if x == b:
            return bigger(a,c)
        else:
            return bigger(a,b)
    

提交回复
热议问题