1. 程式人生 > >手寫堆heap(STL的heap演算法)

手寫堆heap(STL的heap演算法)

大家都很強, 可與之共勉 。

發現自己一千多行的模板有問題23333

template < class T >
class Heap  {
    private :
        T h [N] ;
        int len ;
    public :
        Heap ( )  {  len = 0 ;  }
        inline void push ( const T& x )  {
            h [++ len] = x ;
            std :: push_heap ( h + 1, h + 1 + len, std
:: greater < T > ( ) ) ; } inline T pop ( ) { std :: pop_heap ( h + 1, h + 1 + len, std :: greater < T > ( ) ) ; return h [len --] ; } inline T& top ( ) { return h [1] ; } inline bool empty ( ) { return
len == 0 ; } } ;