C++ Institute CPP Question Answer
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
class compare {
bool reverse;
public:
compare(bool revparam = false){ reverse = revparam;}
bool operator()(int lhs, int rhs) const{
if (reverse)return (lhs > rhs);
elsereturn (lhs < rhs);
}
};
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
priority_queue
priority_queue
compare(false));
while (first.size() > 0){
cout << first.top() << " "; first.pop();
}
while (second.size() > 0) {
cout << second.top() << " ";second.pop();
}
return 0;
}