w****x 发帖数: 2483 | 1 随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;
if (m_ve... 阅读全帖 |
|
w****x 发帖数: 2483 | 2 随手写了一个,没测
class CMinHeap
{
public:
int GetSize() { return m_vec.size(); }
bool empty() { return m_vec.empty(); }
int top() { return m_vec[0]; }
void pop()
{
swap(m_vec[0], m_vec[m_vec.size()-1]);
m_vec.pop_back();
int nCur = 0;
while (2*nCur+1 < m_vec.size())
{
int nSwap = 2*nCur+1;
if (2*nCur+2 < m_vec.size() && m_vec[2*nCur+2] < m_vec[2*nCur+1])
nSwap = 2*nCur+2;
if (m_ve... 阅读全帖 |
|