- """
- heap Sort
- """
- class Heap_Sort:
- def _Sort(self):
- for index in range(1,len(self._mlist)):
- if(self.End == index):
- break
- if(1 == index):
- continue
- while(1):
- parent = index//2
- if(self._mlist[parent]<self._mlist[index]):
- break
- self._mlist[parent],self._mlist[index],index=self._mlist[index],self._mlist[parent],parent
- if(not index!=1):
- break
- def __init__(self,*array):
- self._mlist = list(array)
- self.End = 0
- def print_heapSort(self):
- for index in range(len(self._mlist)-1,0,-1):
- self._mlist[self.End],self._mlist[index],self.End=self._mlist[index],self._mlist[self.End],index
- print([value for value in self._mlist if value])
- self._Sort()
- sort = Heap_Sort(0,23,23,45,15,15,32,47,3)
- sort.print_heapSort()
2018年5月3日 星期四
heap Sort (using Python)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。