#include #include #include using namespace std; struct Process { int id, burst_time, priority, waiting_time, turnaround_time; }; bool priority_comparator(Process a, Process b) { return a.priority < b.priority; } void priority_scheduling(vector& processes) { sort(processes.begin(), processes.end(), priority_comparator); int current_time = 0; for (auto& p : processes) { current_time += p.burst_time; p.turnaround_time = current_time; p.waiting_time = p.turnaround_time - p.burst_time; } } int main() { int num_processes; cout << "Enter the number of processes: "; cin >> num_processes; vector processes(num_processes); cout << "Enter the CPU times: "; for (int i = 0; i < num_processes; ++i) { processes[i].id = i + 1; cin >> processes[i].burst_time; } cout << "Enter the priorities: "; for (int i = 0; i < num_processes; ++i) { cin >> processes[i].priority; } priority_scheduling(processes); double total_waiting_time = 0, total_turnaround_time = 0; for (const auto& p : processes) { total_waiting_time += p.waiting_time; total_turnaround_time += p.turnaround_time; cout << "Process " << p.id << " : Waiting Time : " << p.waiting_time << " Turnaround Time : " << p.turnaround_time << endl; } cout << "Average Waiting time: " << total_waiting_time / num_processes << endl; cout << "Average Turnaround time: " << total_turnaround_time / num_processes << endl; return 0; }