public:
T get(int i) {
return a[i];
}
T remove(int i){
// fill here
}
Exercise 10.3をチェックするプログラムの例をあげ
ます.
#include "BinaryHeap.h"
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
ods::BinaryHeap<int> pq;
pq.add(1);
pq.add(2);
pq.add(10);
pq.add(3); pq.add(4);
pq.add(11); pq.add(12);
pq.add(5); pq.add(6);
for(int i = 0; i < pq.size(); i++)
std::cout << (i == 0 ? "[" : ",") << pq.get(i);
std::cout << "]" << std::endl;
// [1,2,10,3,4,11,12,5,6]
std::cout << pq.remove(1) << std::endl;
// output 2
for(int i = 0; i < pq.size(); i++)
std::cout << (i == 0 ? "[" : ",") << pq.get(i);
std::cout << "]" << std::endl;
// [1,3,10,5,4,11,12,6]
std::cout << pq.remove(2) << std::endl;
// output 10
for(int i = 0; i < pq.size(); i++)
std::cout << (i == 0 ? "[" : ",") << pq.get(i);
std::cout << "]" << std::endl;
// [1,3,6,5,4,11,12]
}
コンパイル, 実行例
bash-3.2$ g++-8 -o checkEx10_3 checkEx10_3.cpp bash-3.2$ ./checkEx10_3 [1,2,10,3,4,11,12,5,6] 2 [1,3,10,5,4,11,12,6] 10 [1,3,6,5,4,11,12]
締切は7/31 23:59
全部の問題が解けなくても,解けたものをなるべく締切前に提出するように.