#include #include #include using namespace std; struct Process { int id; int burstTime; int priority; int waitingTime; int turnaroundTime; }; bool comparePriority(Process a, Process b) { return a.priority > b.priority; // Higher priority first } void calculateTimes(vector& processes) { processes[0].waitingTime = 0; for (int i = 1; i < processes.size(); i++) { processes[i].waitingTime = processes[i - 1].waitingTime + processes[i - 1].burstTime; } for (int i = 0; i < processes.size(); i++) { processes[i].turnaroundTime = processes[i].waitingTime + processes[i].burstTime; } } void priorityScheduling(vector& processes) { sort(processes.begin(), processes.end(), comparePriority); calculateTimes(processes); cout << "\nProcess\tBurst Time\tPriority\tWaiting Time\tTurnaround Time\n"; for (auto& process : processes) { cout << "P" << process.id << "\t\t" << process.burstTime << "\t\t" << process.priority << "\t\t" << process.waitingTime << "\t\t" << process.turnaroundTime << endl; } } int main() { int n; cout << "Enter the number of processes: "; cin >> n; vector processes(n); for (int i = 0; i < n; i++) { processes[i].id = i + 1; cout << "Enter burst time and priority for process " << i + 1 << ": "; cin >> processes[i].burstTime >> processes[i].priority; } priorityScheduling(processes); return 0; }