Movatterモバイル変換


[0]ホーム

URL:


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

Commit6f65106

Browse files
AkashAli506poyea
authored andcommitted
Update heap.py (TheAlgorithms#726)
Added comments for the better understanding of heap.
1 parent88b6caa commit6f65106

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎data_structures/heap/heap.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
exceptNameError:
88
raw_input=input# Python 3
99

10+
#This heap class start from here.
1011
classHeap:
11-
def__init__(self):
12+
def__init__(self):#Default constructor of heap class.
1213
self.h= []
1314
self.currsize=0
1415

@@ -37,13 +38,13 @@ def maxHeapify(self,node):
3738
self.h[m]=temp
3839
self.maxHeapify(m)
3940

40-
defbuildHeap(self,a):
41+
defbuildHeap(self,a):#This function is used to build the heap from the data container 'a'.
4142
self.currsize=len(a)
4243
self.h=list(a)
4344
foriinrange(self.currsize//2,-1,-1):
4445
self.maxHeapify(i)
4546

46-
defgetMax(self):
47+
defgetMax(self):#This function is used to get maximum value from the heap.
4748
ifself.currsize>=1:
4849
me=self.h[0]
4950
temp=self.h[0]
@@ -54,7 +55,7 @@ def getMax(self):
5455
returnme
5556
returnNone
5657

57-
defheapSort(self):
58+
defheapSort(self):#This function is used to sort the heap.
5859
size=self.currsize
5960
whileself.currsize-1>=0:
6061
temp=self.h[0]
@@ -64,7 +65,7 @@ def heapSort(self):
6465
self.maxHeapify(0)
6566
self.currsize=size
6667

67-
definsert(self,data):
68+
definsert(self,data):#This function is used to insert data in the heap.
6869
self.h.append(data)
6970
curr=self.currsize
7071
self.currsize+=1
@@ -74,7 +75,7 @@ def insert(self,data):
7475
self.h[curr]=temp
7576
curr=curr/2
7677

77-
defdisplay(self):
78+
defdisplay(self):#This function is used to print the heap.
7879
print(self.h)
7980

8081
defmain():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp