Saturday, October 3, 2020

Plane scheduler system (Model)


#include <iostream>

#include <vector>

#include <map>

#include <queue>


using namespace std;


enum class type {

    CARGO,

    PASSENGER

};


enum class category {

    SMALL,

    LARGE

};


class plane {

private:

    type tt_;

    category cc_;


public:

    plane(type tt, category cc) {

        tt_ = tt;

        cc_ = cc;

    }

    

    type getType() const {

        return tt_;

    }

    

    category getCategory() const {

        return cc_;

    }

};



struct comp {

    bool operator()(const plane& p1, const plane& p2) {

        if (int(p1.getCategory()) > int(p2.getCategory())) {

            return true;

        } else if (int(p1.getCategory()) == int(p2.getCategory()) &&

                    int(p1.getType()) > int(p2.getType())) {

            return true;

        } else {

            return false;

        }

    }

};


class PlaneSystem {

private:

    priority_queue<plane, vector<plane>, comp> pq;

    

public:

    bool schedule(plane& p1) {

        if (pq.empty()) {

            return false;

        }

        p1 = pq.top(); pq.pop();

        return true;

    }

    

    void add(plane p1) {

        pq.push(p1);

    }

};


int main()

{

    cout << "Hello World" << endl;

    PlaneSystem s1;

    

    return 0;

}


No comments:

Post a Comment