Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

實作heap具insert delete功能

急需

insert

delete

功能的heap程式

1 Answer

Rating
  • 鳳綾
    Lv 4
    1 decade ago
    Favorite Answer

    heap,具insert delete,如下:

    template<class T>struct Heap

    {

    vector<T>v;

    Heap(){make_heap(v.begin(),v.end());}

    void Insert(T o){v.push_back(o); push_heap(v.begin(),v.end());}

    T Delete(){T o=*(v.begin());pop_heap(v.begin(),v.end());v.pop_back();return o;}

    };

Still have questions? Get your answers by asking now.