priority queue - Using priority_queue in C++ -
i'm trying write simple function returns time wait car arrives @ gate of parking lot. i'm using priority_queue purpose , code doesn't seem compile.
here's function
std::time_t waitingtime(std::vector<car* > v){ //std::unordered_map<std::time_t, std::string> lookup; std::vector<std::time_t> timevector; std::priority_queue<std::time_t, timevector, std::greater<std::time_t>> q; for(auto = v.begin(); != v.end(); it++){ car* c = *it; timevector.push_back(c->exit); //lookup[c->exit] = c->id; } for(std::time_t t :timevector){ q.push(t); } const std::time_t t = q.top(); q.pop(); return t; };
here's driver code
std::time_t = time(0); car* c1 = new car("a", now+2, now+4); car* c2 = new car("a", now, now+3); car* c3 = new car("a", now, now+1); std::vector<car* > v; v.push_back(c1); v.push_back(c2); v.push_back(c3); std::time_t t = waitingtime(v); std::cout<<t<<std::endl;
here's compilation error.
38: error: template argument template type parameter must type std::priority_queue<std::time_t, timevector, std::greater<std::time_t>> q;
you need provide types arguments template, not objects. declaration of queue should following:
std::priority_queue<std::time_t> queue;
note, didn't specify other template arguments - default needed.
Comments
Post a Comment