Пример #1
0
def insertion_sort(list):
    n = len(list)
    for i in range(0, n - 1):
        min_index = i
        for j in range(i + 1, n):
            if list[j].speed > list[min_index].speed:
                min_index = j
            Counter.compare_count()
        list = swap(list, i, min_index)
        Counter.exchange_count()
    return list
Пример #2
0
def Selection(list):
    L = len(list)
    for i in range(0, L - 1):
        min = i
        for j in range(i + 1, L):
            if list[j].rating > list[min].rating:
                min = j
            Counter.compare_count()
        temp = list[i]
        list[i] = list[min]
        list[min] = temp
        Counter.exchange_count()
    return list
Пример #3
0
def partition(arr, low, high):
    i = (low - 1)
    pivot = arr[high]

    for j in range(low, high):
        if arr[j].height <= pivot.height:
            i = i + 1
            temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp
        Counter.compare_count()
    Counter.exchange_count()
    temp = arr[i + 1]
    arr[i + 1] = arr[high]
    arr[high] = temp
    Counter.exchange_count()
    return (i + 1)
Пример #4
0
    def partition(self, low, hi):
        pivot_index = self.get_pivot(low, hi)
        pivot_value = self.sort_list[pivot_index]
        self.sort_list[pivot_index], self.sort_list[low] = self.sort_list[
            low], self.sort_list[pivot_index]
        Counter.exchange_count()
        border = low

        for i in range(low, hi + 1):
            if self.sort_list[i].price < pivot_value.price:
                border += 1
                self.sort_list[i], self.sort_list[border] = self.sort_list[
                    border], self.sort_list[i]
                Counter.exchange_count()
            Counter.compare_count()
        self.sort_list[low], self.sort_list[border] = self.sort_list[
            border], self.sort_list[low]
        Counter.exchange_count()

        return border
Пример #5
0
 def get_pivot(self, low, hi):
     mid = int((hi + low) / 2)
     pivot = hi
     Counter.compare_count()
     if self.sort_list[low].price < self.sort_list[mid].price:
         if self.sort_list[mid].price < self.sort_list[hi].price:
             pivot = mid
         Counter.compare_count()
     elif self.sort_list[low].price < self.sort_list[hi].price:
         pivot = low
     Counter.compare_count()
     return pivot