0

Getting error while declaring priority queue like this with a custom operator

struct compare1{
         bool operator()(Interval &s1,Interval &s2){
             if(s1.start!=s2.start)return s1.start<s2.start;
             return s1.end<s2.end;
         }
     };
priority_queue(Interval,vector<Interval>,compare1)p;

Error->/code/Solution.cpp: In member function 'int Solution::minMeetingRooms(std::vector&)': /code/Solution.cpp:33:23: error: missing template arguments before '(' token priority_queue(Interval,vector,compare1)p;

^ /code/Solution.cpp:33:32: error: expected primary-expression before ',' token priority_queue(Interval,vector,compare1)p;

^ /code/Solution.cpp:33:49: error: expected primary-expression before ',' token priority_queue(Interval,vector,compare1)p; ^

/code/Solution.cpp:33:58: error: expected primary-expression before ')' token priority_queue(Interval,vector,compare1)p;

My whole code

class Solution {
public:
    /**
     * @param intervals: an array of meeting time intervals
     * @return: the minimum number of conference rooms required
     * 
     */
     static bool compare(Interval s1 ,Interval s2){
         if(s1.start!=s2.start)return s1.start<s2.start;
         return s1.end<s2.end;
     }

     struct compare1{
         bool operator()(Interval &s1,Interval &s2){
             if(s1.start!=s2.start)return s1.start<s2.start;
             return s1.end<s2.end;
         }
     };
    int minMeetingRooms(vector<Interval> &intervals) {

        sort(intervals.begin(),intervals.end(),compare);
        priority_queue(Interval,vector<Interval>,compare1)p;
        p.push(intervals[0]);
        int ans = 0;
        for(int i=1;i<intervals.size();i++){
            Interval curr = interevals[i];
            Interval earliest = p.top();
            p.pop();


            if(earliest.end<curr.start){
                earliest.start = min(earliest.start,interevals[i].start);
                earliest.end = max(earliest.end,intervals[i].end);
                pq.push(earliest);
                ans++;
            }
            else{
                p.push(interevals[i]);
            }

        }
        return ans;


    }
};
1

1 Answer 1

2

Use this,

priority_queue<Interval,vector<Interval>,compare1> p;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.