This code relies on Python3.7.4
I'm learning Heapsort in python 3. Please show me the errors in my code. Runs on my computer but tell me if Python rules or not.
class Heap:
'''constructor'''
def __init__(self,lis):
self.lis=lis
self.a=[]
def heapify(self,i):
self.r=(i-1)//2 #To get the root node
'''To swap value'''
if self.lis[i]<self.lis[self.r]:
self.lis[i],self.lis[self.r]=self.lis[self.r],self.lis[i]
def heapSort(self):
# Build a minheap.
for j in range(len(self.lis)):
for i in range(len(self.lis)-1,-1,-1):
if i==0:
self.a.append(self.lis[0])
self.lis.remove(self.lis[0])
else:
self.heapify(i)
else:
return self.a
obj=Heap([5,4,3,2,1])
print(obj.heapSort())