• 鸡尾酒排序代码中,已经排序好的不用再遍历了

    def cocktail_sort!
        f  = 0
        while f < self.length/2
            i = f
            while i < self.length - 1 - f
                self[i], self[i+1] = self[i+1], self[i] if self[i] > self[i+1]
                i += 1;
            end
            t = self.length - 1 - f
            while t > f
                self[t], self[t-1] = self[t-1], self[t] if self[t] < self[t-1]
                t -= 1
            end
            f += 1
        end
        self
    end