Skip to main content
added 75 characters in body
Source Link
user33306
user33306

A few things I noticed:

the standard library includes a swap function I would suggest using it or at least put the swap algorithm in its own function.

Instead of synchronized collections, it would simplify and increase maintainability to have an embedded class to hold the times. This way you have one collection and the times are automatically synchronized. Implementing the standard comparison operators(<,==,>) allows you to simplify the sorting:

#include <vector>

using uint = unsigned int;
using std::vector;
class Scheduler
{
    class ProcessTimes
    {
        uint arrivalTime = 0;
        uint burstTime = 0;
        uint waitingtime = 0;
        uint turnAroundTime = 0;
        uint priority = 0;
    public:
        ProcessTimes();
        ProcessTimes(uint arrival, uint burst, uint waiting, uint turnAround, uint priority) :
            arrivalTime(arrival),
            burstTime(burst),
            waitingtime(waiting),
            turnAroundTime(turnAround),
            priority(priority)
        {}
        ~ProcessTimes();
        bool operator ==(ProcessTimes& other) { return arrivalTime == other.arrivalTime; }
        bool operator <(ProcessTimes& other) { return arrivalTime < other.arrivalTime; }
        bool operator >(ProcessTimes& other) { return arrivalTime > other.arrivalTime; }
        int compareTo(ProcessTimes& other) { return arrivalTime < other.arrivalTime ? -1 
                                            : arrivalTime > other.arrivalTime ? 1 :0; }
    };
    vector<ProcessTimes> times;
};

Once you have this done, I would suggest looking into a Heap based Priority Queuemin Heap Priority Queue.

A few things I noticed:

the standard library includes a swap function I would suggest using it or at least put the swap algorithm in its own function.

Instead of synchronized collections, it would simplify and increase maintainability to have an embedded class to hold the times. This way you have one collection and the times are automatically synchronized. Implementing the standard comparison operators(<,==,>) allows you to simplify the sorting:

#include <vector>

using uint = unsigned int;
using std::vector;
class Scheduler
{
    class ProcessTimes
    {
        uint arrivalTime = 0;
        uint burstTime = 0;
        uint waitingtime = 0;
        uint turnAroundTime = 0;
        uint priority = 0;
    public:
        ProcessTimes();
        ProcessTimes(uint arrival, uint burst, uint waiting, uint turnAround, uint priority) :
            arrivalTime(arrival),
            burstTime(burst),
            waitingtime(waiting),
            turnAroundTime(turnAround),
            priority(priority)
        {}
        ~ProcessTimes();
        bool operator ==(ProcessTimes& other) { return arrivalTime == other.arrivalTime; }
        bool operator <(ProcessTimes& other) { return arrivalTime < other.arrivalTime; }
        bool operator >(ProcessTimes& other) { return arrivalTime > other.arrivalTime; }
        int compareTo(ProcessTimes& other) { return arrivalTime < other.arrivalTime ? -1 
                                            : arrivalTime > other.arrivalTime ? 1 :0; }
    };
    vector<ProcessTimes> times;
};

Once you have this done, I would suggest looking into a Heap based Priority Queue.

A few things I noticed:

the standard library includes a swap function I would suggest using it or at least put the swap algorithm in its own function.

Instead of synchronized collections, it would simplify and increase maintainability to have an embedded class to hold the times. This way you have one collection and the times are automatically synchronized. Implementing the standard comparison operators(<,==,>) allows you to simplify the sorting:

#include <vector>

using uint = unsigned int;
using std::vector;
class Scheduler
{
    class ProcessTimes
    {
        uint arrivalTime = 0;
        uint burstTime = 0;
        uint waitingtime = 0;
        uint turnAroundTime = 0;
        uint priority = 0;
    public:
        ProcessTimes();
        ProcessTimes(uint arrival, uint burst, uint waiting, uint turnAround, uint priority) :
            arrivalTime(arrival),
            burstTime(burst),
            waitingtime(waiting),
            turnAroundTime(turnAround),
            priority(priority)
        {}
        ~ProcessTimes();
        bool operator ==(ProcessTimes& other) { return arrivalTime == other.arrivalTime; }
        bool operator <(ProcessTimes& other) { return arrivalTime < other.arrivalTime; }
        bool operator >(ProcessTimes& other) { return arrivalTime > other.arrivalTime; }
        int compareTo(ProcessTimes& other) { return arrivalTime < other.arrivalTime ? -1 
                                            : arrivalTime > other.arrivalTime ? 1 :0; }
    };
    vector<ProcessTimes> times;
};

Once you have this done, I would suggest looking into a min Heap Priority Queue.

Source Link
user33306
user33306

A few things I noticed:

the standard library includes a swap function I would suggest using it or at least put the swap algorithm in its own function.

Instead of synchronized collections, it would simplify and increase maintainability to have an embedded class to hold the times. This way you have one collection and the times are automatically synchronized. Implementing the standard comparison operators(<,==,>) allows you to simplify the sorting:

#include <vector>

using uint = unsigned int;
using std::vector;
class Scheduler
{
    class ProcessTimes
    {
        uint arrivalTime = 0;
        uint burstTime = 0;
        uint waitingtime = 0;
        uint turnAroundTime = 0;
        uint priority = 0;
    public:
        ProcessTimes();
        ProcessTimes(uint arrival, uint burst, uint waiting, uint turnAround, uint priority) :
            arrivalTime(arrival),
            burstTime(burst),
            waitingtime(waiting),
            turnAroundTime(turnAround),
            priority(priority)
        {}
        ~ProcessTimes();
        bool operator ==(ProcessTimes& other) { return arrivalTime == other.arrivalTime; }
        bool operator <(ProcessTimes& other) { return arrivalTime < other.arrivalTime; }
        bool operator >(ProcessTimes& other) { return arrivalTime > other.arrivalTime; }
        int compareTo(ProcessTimes& other) { return arrivalTime < other.arrivalTime ? -1 
                                            : arrivalTime > other.arrivalTime ? 1 :0; }
    };
    vector<ProcessTimes> times;
};

Once you have this done, I would suggest looking into a Heap based Priority Queue.