//C++??????????????????
#include<iostream>
using namespace std;
class BinaryHeap
{
private:
int cap;  //?????е??????
int size; //??????????
int* datas; //????????
public:
explicit BinaryHeap(int cap_) :cap(cap_)?? size(0)
{
datas = new int[cap];
}
~BinaryHeap(){ delete datas; }
void Insert(int);
int DeleteMin();
};
//?????????????????±??0?????i???????i*2+1?i???????????i*2+2?i???????????i/2?i??????
void BinaryHeap::Insert(int data)
{
int i;
for (i = size; i / 2 >= 0 && datas[i / 2] > data; i /= 2) //????
{
datas[i] = datas[i / 2];
}
datas[i] = data;
size++;
}
int BinaryHeap::DeleteMin()
{
int i = 0?? child = 0;
int lastdata = datas[--size];
int mindata = datas[0];
for (i = 0; i * 2 + 1 <= size-1; i = child)   //????
{
child = i * 2 + 1;
if (child < size-1 && datas[child + 1] < datas[child])
{
child++;
}
if (lastdata > datas[child])
{
datas[i] = datas[child];
}
else
{
break;
}
}
datas[i] = lastdata;
return mindata;
}
int main()
{
BinaryHeap t(400);
for (int i = 0; i < 100; i++)
t.Insert(i);
for (int i = 200; i > 100; i--)
t.Insert(i);
for (int i = 0; i < 200; i++)
cout << t.DeleteMin() << endl;
cin.get();
return 0;
}