Exemplo n.º 1
0
int main () {
  MinMaxHeap<int> *heap = new MinMaxHeap<int>();
  int N;
  cin >> N;
  for (; N > 0; --N) {
    char op, sub_op;
    int elem;
    cin >> op;
    if (op == 'i') {
      cin >> elem;
      heap->insert(elem);
    }
    else if (op == 'g') {
int main()
{
	MinMaxHeap<int> heap;
	heap.push(4);
	heap.push(3);
	heap.push(7);
	heap.push(2);
	heap.push(11);
	heap.push(0);
	heap.push(77);
	heap.push(99);
	heap.push(13);
	while (heap.Count() > 0)
	{
		cout << *(heap.pop()) << endl;
	}
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char const *argv[])
{
    srand(time(NULL));
    auto random = []() {
        int max = 50;
        int min = -max;
        return min + (rand() % (int)(max - min + 1));
    };

    std::vector<int> test_permutation;
    for (int i = 0; i < 987; ++i) {
        test_permutation.push_back(random());
    }

    for (int test = 0; test < 10000; ++test) {
        // if (test % 10 == 0) {
        //     std::cout << "Test NO " << test << std::endl;
        // }
        std::random_shuffle(test_permutation.begin(), test_permutation.end());
        MinMaxHeap<int> heap;
        for (const auto n : test_permutation) {
            // std::cout << "inserting: " << n << "\n";
            heap.insert(n);
            // std::cout << "inserting: " << n * 49739 % 50 << "\n";
            heap.insert(n * 49739 % 50);
            // std::cout << "Deleting min.. " << "\n";
            heap.deleteMin();
        }
        for (const auto n : test_permutation) {
            (void) n;
            // std::cout << "Deleting min.. " << "\n";
            heap.deleteMin();
            // std::cout << "Deleting max.. " << "\n";
            heap.deleteMax();
        }
    }
    return 0;
}