测试Std:heap

void test1() {
  vector va;
  int a[] = {1,3,5,3,6,4,7,4,9};
  for (int i = 0; i < sizeof(a)/sizeof(int); i++) {
    va.push_back(a[i]);
  }
  cout << va.size() << endl;

  make_heap(va.begin(), va.end());
  print_vector(va);
  size_t n = va.size();
  for (int i = n; i > 0; i--) {
    pop_heap(va.begin(), va.begin() + i);
    print_vector(va);
  }

}
template 
void print_vector(const vector& v) {
  for (size_t i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}


你可能感兴趣的:(C/C++)