Create a program in C/C++ for Shortest Job First (SJF) Scheduling for the following processes that are in ready queue at 0 timestamp
Process CPU Burst Time
P1 1
P2 4
P3 2
P4 10
P5 7
#include <iostream>
const int M = 11;
template <class T>
class Queue
{
private:
int top;
int bottom;
static int c;
T st[M];
public:
class Full {};
class Empty {};
Queue();
void push(T value);
T pop ();
};
template <class T>
int Queue<T>::c = 0;
template <class T>
Queue<T>::Queue():top(10), bottom(10){}
template <class T>
void Queue<T>::push(T value)
{
if(c > M-1){
throw Full();
}
st[top--] = value;
++c;
if (top==-1) {
bottom = 2;
}
}
template <class T>
T Queue<T>::pop()
{
if(c == 0)
{
throw Empty();
}
if(bottom==0)
{
top = 10;
bottom = 10;
c--;
return st[0];
}
else c--;
return st[bottom--];
}
struct Process
{
int i;
Process(){}
Process(int time)
{
i = time;
}
};
int main()
{
Queue<Process> q;
Process P1(1);
Process P2(4);
Process P3(2);
Process P4(10);
Process P5(7);
q.push(P1);
q.push(P2);
q.push(P3);
q.push(P4);
q.push(P5);
return 0;
}
Comments
Leave a comment