Skip to content

Add/priority scheduling#3145

Open
Shubhangam-Singh wants to merge 2 commits into
TheAlgorithms:masterfrom
Shubhangam-Singh:add/priority-scheduling
Open

Add/priority scheduling#3145
Shubhangam-Singh wants to merge 2 commits into
TheAlgorithms:masterfrom
Shubhangam-Singh:add/priority-scheduling

Conversation

@Shubhangam-Singh
Copy link
Copy Markdown

Description of Change

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

Implements preemptive Round Robin (RR) scheduling in C++17 following
the TheAlgorithms/C-Plus-Plus code style.

Key features:
- Supports processes with different arrival times
- Uses std::queue<uint32_t> for the circular ready queue
- Class template RoundRobin<S,T,E> with addProcess() / scheduleForRR()
  / printResult() methods, wrapped in namespace cpu_scheduling_algorithms::round_robin
- Doxygen comments on all types, functions, and parameters
- 5 self-test cases validated with assert(), including:
    - Same-arrival-time scenario (quantum=2, three processes)
    - Single-process trivial case (no waiting, no preemption)
    - Burst == quantum case (no preemption, sequential completion)
    - Duplicate process ID guard
    - Different arrival times cross-validated against a reference impl
…ptive)

Implements both Non-Preemptive and Preemptive Priority Scheduling in
C++17 following the TheAlgorithms/C-Plus-Plus code style.

Convention: lower priority number = higher urgency (standard OS convention).

Key features:
- NonPreemptivePriority<S,T,E,P>: event-driven, min-heap ready queue;
  running process is never preempted
- PreemptivePriority<S,T,E,P>: event-driven (jumps between arrivals and
  finish events); preempts current process when a higher-priority one arrives
- Both classes: addProcess() / scheduleForNPP|PP() / printResult()
- Wrapped in namespace cpu_scheduling_algorithms::priority_scheduling
- Full Doxygen comments on all types, classes, and methods
- 6 assert()-based self-tests:
    Test 1: Non-preemptive GFG example (different arrivals) — P1 WT=0, P2 WT=3, P3 WT=4
    Test 2: Non-preemptive single process — WT=0
    Test 3: Non-preemptive duplicate PID guard
    Test 4: Preemptive different arrivals — P1 CT=10, P2 CT=5, P3 CT=15
    Test 5: Preemptive same arrival — P3(pri1) CT=6, P1(pri2) CT=13, P2(pri3) CT=17
    Test 6: Preemptive single process — WT=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant