[ create a new paste ] login | about

Link: http://codepad.org/sPyK3t9t    [ raw code | output | fork ]

maweaver - C++, pasted on Sep 24:
#include <iostream>
#include <queue>

struct Bill {
    Bill(const std::string &_name, int _value) : name(_name), value(_value) { }

    std::string name;
    int value;

    bool operator<(const Bill &other) const {
      return value < other.value;
    }
};

int main(int argc, char **argv) {
    Bill one("$1", 1);
    Bill five("$5", 5);
    Bill ten("$10", 10);
    Bill twenty("$20", 20);
 
    std::priority_queue<Bill> bills;
    bills.push(five);
    bills.push(one);
    bills.push(ten);
    bills.push(twenty);

    while(!bills.empty()) {
        std::cout << bills.top().name << " ";
        bills.pop();
    }

    std::cout << "\n";
    return 0;
}


Output:
1
$20 $10 $5 $1 


Create a new paste based on this one


Comments: