cpp2html 0.1-alpha © 2002 Andrea Leofreddi. To get the source click here

// Esempio 3: Heap
#include <iostream>
#include <string>
#include <math.h>
#include "es3.h"

using namespace std;

int main() {
	Heap<string> myheap(10);

	try {
		myheap.push(string("nove"), 9);
		myheap.push(string("tre"), 3);
		myheap.push(string("sei"), 6);
		myheap.push(string("due"), 2);
		myheap.push(string("cinque"), 5);
		myheap.push(string("sette"), 7);
		myheap.push(string("uno"), 1);
		myheap.push(string("quattro"), 4);
		myheap.push(string("otto"), 8);
		myheap.push(string("dieci"), 10);
	//	myheap.push(string("undici"), 11); // heap overflow

		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
		cout << "pop: " << myheap.pop() << endl;
	//	cout << "pop: " << myheap.pop() << endl; // heap underflow
		myheap.pop();
	}

	catch(int e) {
		cout << "catch: eccezione " << ((e == Heap<int>::heap_underflow) ? "heap underflow" : " heap overflow") << endl;
	}
}