-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpriority_non.c
82 lines (73 loc) · 2.43 KB
/
priority_non.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#define MAX_SIZE 50
// Turnaround Time (TAT):
// It is the time interval from the time of submission of a process to the time of the completion of the process.
// Turn Around Time = Completion Time - Arrival Time
// Waiting Time (WT):
// The time spent by a process waiting in the ready queue for getting the CPU.
// Waiting Time = Turn Around Time - Burst Time
void bubblesort(int arr[],int arr2[],int arr3[],int arr4[],int size);
void swap(int *a,int *b);
int main(){
int n,time=0;
float avgwt=0,avgtat=0;
int PRIORITY[MAX_SIZE];
int AT[MAX_SIZE],BT[MAX_SIZE],CT[MAX_SIZE],WT[MAX_SIZE],TAT[MAX_SIZE];
int P[MAX_SIZE];
printf("Enter the number of processes : ");
scanf("%d",&n);
printf("Enter the Arrival Time and Burst Time :\n");
printf("\tArrival Time\tBurst Time\tPriority:\n");
for(int i =0; i<n; i++){
printf("p[%d] : ",i+1);
scanf("%d",&AT[i]);
scanf("%d",&BT[i]);
scanf("%d",&PRIORITY[i]);
P[i] = i+1;
}
bubblesort(PRIORITY,BT,P,AT,n);
time = AT[0]; // initial time
for(int i =0;i<n;i++){
time += BT[i]; // increasing the Time
CT[i] = time;
TAT[i] = CT[i] - AT[i];
WT[i] = TAT[i]-BT[i];
avgtat+=TAT[i];
avgwt+=WT[i];
}
avgtat /= n;
avgwt /= n;
printf("\n*******************************************************\n\n");
printf("Process\tPriority\tArrival Time\tBurst Time\tCompletion\tTurnAround\tWaiting\n");
for(int i=0;i<n;i++){
printf("P[%d]\t",P[i]);
printf("%d\t",PRIORITY[i]);
printf("\t%d\t",AT[i]);
printf("\t%d\t",BT[i]);
printf("\t%d\t",CT[i]);
printf("\t%d\t",TAT[i]);
printf("\t%d\t\n",WT[i]);
}
printf("\nThe Average TurnAroundTime : %f",avgtat);
printf("\nThe Average WaitingTime : %f",avgwt);
return 0;
}
void swap(int *a,int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void bubblesort(int arr[],int arr2[],int arr3[],int arr4[],int size){
for (int i = 0; i < size-1; i++){
int temp = 0;
for (int j = 0; j < size - i - 1; j++){
if (arr[j] > arr[j + 1]){
swap(&arr[j],&arr[j+1]);
swap(&arr2[j],&arr2[j+1]);
swap(&arr3[j],&arr3[j+1]);
swap(&arr4[j],&arr4[j+1]);
}
}
}
}