def increase_key(self,i,key):
		if key<self.queue[i]:
			raise "new key is samller than current key"
		self.queue[i]=key
		while i>1 and self.queue[parent(i)]<self.queue[i]:
			self.queue[i],self.queue[parent(i)]=self.queue[parent(i)],self.queue[i]
			i=parent(i)
def heap_increase_key(a, i, key):
    if key < a[i]:
        print('error: new key is smaller than current key')
    a[i] = key
    while i > 0 and a[heap_sort.parent(i)] < a[i]:
        a[i], a[heap_sort.parent(i)] = a[heap_sort.parent(i)], a[i]
        i = heap_sort.parent(i)
Beispiel #3
0
def heap_increase_key(arr, i, key):
    build_max_heap(arr)
    if key < arr[i]:
        print('New key is smaller then current key')
    arr[i] = key
    while i > 0 and arr[parent(i)] < arr[i]:
        arr[i], arr[parent(i)] = arr[parent(i)], arr[i]
        i = parent(i)
def increase_key(heap, i, key):
    if key < heap.at(i):
        raise KeyNonIncreaseException
    heap.put(i, key)
    while i > 0:
        par = hs.parent(i)
        par_val = heap.at(par)
        if par_val < key:
            heap.put(i, par_val)  # bubble up the heap -> NOT WORKING
            heap.put(par, key)
            i = par
        else:
            break