This is The function i have written to get waiting times of processes
some one please help me to solve this
class NonPreemptive
{
public:
int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess)
{
int ct[5],temp,j;
int* wt = (int*)malloc(sizeof(int)* 5);
wt[0]=0,j=0;
for(int i=process[j++];i<=nProcess;i++)
{
if((arrivalTime[0]==0)&&(arrivalTime[j]<arrivalTime[j+1])&&(0<burstTime[j]<10))
{
ct[i]=arrivalTime[i]+burstTime[i]+wt[i];
wt[i+1]=ct[i]-arrivalTime[i+1];
if((arrivalTime[j+1]+burstTime[j+1])>(arrivalTime[j+2]+burstTime[j+2]))
int temp=process[j+1];process[j+1]=process[j+2];process[j+2]=temp;
}
else return NULL;
}return wt;
}
};
I am working on Non preemptive scheduling algorithm.....
My below function needs to written the waiting time of the processes 1,2,3,4,
and below are the 3 test cases needs to be satisfied.
Test case 1:
int proc[] = {1, 2, 3, 4};
int arrivalTime[] = {0, 2, 4, 5};
int burstTime[] = {7, 4, 1, 4};
Test case 2:
int proc[] = {1, 2, 3};
int arrivalTime[] = {0, 4, 8};
int burstTime[] = {6, 2, 1};
Test case 3:
int proc[] = {1, 2, 3, 4};
int aTime[] = {2, 0, 4, 5};
int bTime[] = {7, 4, 1, 4};
we have given a constraints like below to satisfy:
i) If more than 1 processes have arrived before the completion of current process
then allocation should be done for the process which having min value of
(arrivalTime+burstTime);
ii) Burst time of processes should be between 0<burst time<10;
ii) arrival Time of the first process should be 0;
vi)arrival Times should be in increasing order.
v)if above condition fails then return NULL;
output for above should be:
test case1: {0,6,3,7}
test case2:{0,2,0}
test case3:{NULL}