Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 13bbed8

Browse files
committed
Added self to function def
1 parent f94fd05 commit 13bbed8

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

‎heap_structure.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Heap(object):
2-
2+
33
HEAP_SIZE = 10;
4-
4+
55
def __init__(self):
66
self.heap = [0]*Heap.HEAP_SIZE
77
self.currentPosition = -1
8-
8+
99
def insert(self, item):
10-
10+
1111
# if heap is full , we print a notification
1212
if self.isFull():
1313
print("Heap is full")
@@ -16,7 +16,7 @@ def insert(self, item):
1616
self.currentPosition+=1
1717
self.heap[self.currentPosition] = item
1818
self.fixUp(self.currentPosition)
19-
19+
2020
def fixUp(self, index):
2121
parentIndex = int((index-1)/2)
2222
while parentIndex >=0 and self.heap[parentIndex] < self.heap[index]:
@@ -27,54 +27,54 @@ def fixUp(self, index):
2727
# update the index and parentIndex
2828
index = parentIndex
2929
parentIndex = int((index-1)/2)
30-
30+
3131
def fixDown(self, index, upto):
3232
if upto < 0:
3333
upto = self.currentPosition
34-
34+
3535
while index<=upto:
3636
leftChild = 2*index+1
3737
rightChild = 2*index+2
38-
38+
3939
if leftChild <= upto:
4040
childToSwap = 0
4141
else:
4242
if self.heap[leftChild] < self.heap[rightChild]:
4343
childToSwap = leftChild
4444
else:
4545
childToSwap = rightChild
46-
46+
4747
if self.heap[index] < self.heap[childToSwap]:
4848
temp = self.heap[index]
4949
self.heap[index] = self.heap[childToSwap]
5050
self.heap[childToSwap] = temp
5151
else:
5252
break
53-
53+
5454
index = childToSwap
55-
55+
5656
else:
5757
return
58-
58+
5959
def heapSort(self):
6060
for i in range(0, self.currentPosition+1):
6161
temp = self.heap[0]
6262
print("%d"%temp)
6363
self.heap[0] = self.heap[self.currentPosition-i]
6464
self.heap[self.currentPosition-i] = temp
6565
self.fixDown(0, self.currentPosition-i-1)
66-
67-
def getMax():
66+
67+
def getMax(self):
6868
result = self.heap[0]
6969
self.currentPosition-=1
7070
self.heap[0] = self.heap[self.currentPosition]
7171
del self.heap[self.currentPosition]
7272
self.fixDown(0, -1)
7373
return result
74-
74+
7575
def isFull(self):
7676
return self.currentPosition == Heap.HEAP_SIZE
77-
77+
7878
some_heap=Heap()
7979
some_heap.insert(12)
8080
some_heap.insert(-3)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /