コード例 #1
0
def heap_sort(heap):
    build_max_heap(heap)
    heap_size = len(heap) - 1
    for i in range(heap_size, 1, -1):
        heap[1], heap[i] = heap[i], heap[1]
        heap_size -= 1
        max_heapify(heap, heap_size, 1)
コード例 #2
0
ファイル: heap.py プロジェクト: partha101/SaaS
	def delete_item(self,k):
		for i in self.list:
			if i==k:
				index=self.list.index(i)
				break
		self.list[len(self.list)-1],self.list[index]=self.list[index],self.list[len(self.list)-1]
		self.list.pop()
		build_max_heap(self.list) 
コード例 #3
0
 def delete_item(self, k):
     for i in self.list:
         if i == k:
             index = self.list.index(i)
             break
     self.list[len(self.list) -
               1], self.list[index] = self.list[index], self.list[
                   len(self.list) - 1]
     self.list.pop()
     build_max_heap(self.list)
コード例 #4
0
ファイル: heap_sort.py プロジェクト: cre8tion/Algorithms
def heap_sort(array):
    array = build_max_heap(array)
    sorted_array = []
    # Loop till array has 1 element
    for i in range(len(array) - 1, 0, -1):
        array = swap(i, 0, array)
        maxnum = array[len(array) - 1]
        array.pop(len(array) - 1)
        sorted_array.insert(0, maxnum)
        max_heapify(array, 0)
    # Insert last element of heap
    sorted_array.insert(0, array[0])
    return sorted_array
コード例 #5
0
ファイル: heap.py プロジェクト: partha101/SaaS
	def insert(self,x):
		self.list.append(x)
		build_max_heap(self.list) 
コード例 #6
0
ファイル: heap.py プロジェクト: partha101/SaaS
	def change_key(self,i,key):
		if key<self.list[i]:
			print "no insertion"
		else :
			self.list[i]=key
			build_max_heap(self.list)   
コード例 #7
0
ファイル: heap.py プロジェクト: partha101/SaaS
	def extract_max(self):
		self.list[len(self.list)-1],self.list[0]=self.list[0],self.list[len(self.list)-1]
		print self.list.pop()
		build_max_heap(self.list) 
コード例 #8
0
 def insert(self, x):
     self.list.append(x)
     build_max_heap(self.list)
コード例 #9
0
 def change_key(self, i, key):
     if key < self.list[i]:
         print "no insertion"
     else:
         self.list[i] = key
         build_max_heap(self.list)
コード例 #10
0
 def extract_max(self):
     self.list[len(self.list) -
               1], self.list[0] = self.list[0], self.list[len(self.list) -
                                                          1]
     print self.list.pop()
     build_max_heap(self.list)