forked from csajce/2021hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdcsd.c
151 lines (138 loc) · 3.27 KB
/
sdcsd.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include<stdio.h>
#include<stdlib.h>
struct node
{
int ProcessID;
int busttime;
int startingtime;
int waitingtime;
int leftback;
int turnaroundtime;
struct node *link;
};
void main()
{
int i;
int root=1;
int id;
int bustt;
int k;
int chip=0;
int count;
int pitin;
int totalwait,totalturn;
int currenttime;
int timeslice;
struct node *temp, *head,*tail,*ptr1,*ptr,*temp1;
printf("Enter the Time Slice");
scanf("%d",×lice);
while(root=1)
{
temp=(int*)malloc(sizeof(struct node*));
if (temp==NULL)
{
printf("Memmory overflow");
break;
}
else
{
printf("3455");
temp->link=NULL;
printf("456");
printf("Enter The process ID");
scanf("%d",&id);
printf("123");
temp->ProcessID=id;
printf("345");
printf("Enter Bust Time ");
scanf("%d",&bustt);
temp->leftback=bustt;
temp->busttime=bustt;
if (head==NULL)
{
head=temp;
}
else
{
ptr=head;
while (ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=temp;
}
}
printf("Do You Want Enter another Process? Yes-1 & No- 0");
scanf("%d",&root);
}
printf ("\n \n Deatails You Enterd\n" );
ptr=head;
count=0;
while(ptr!=NULL)
{
printf("\nProcess ID=%d",ptr->ProcessID);
printf("\nBust Time=%d",ptr->busttime);
ptr=ptr->link;
count=count+1;
}
currenttime=0;
pitin=0;
ptr=head;
while (ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=head;
ptr=head;
while(chip<=count)
{
if (ptr->leftback==0)
{
ptr=ptr->link;
}
else
{
while(pitin<=timeslice)
{
if (ptr->busttime==ptr->leftback)
{
ptr->waitingtime=currenttime;
ptr->startingtime=currenttime;
}
currenttime=currenttime+1;
ptr->leftback=ptr->leftback-1;
pitin=pitin+1;
if (ptr->leftback==0)
{
ptr->turnaroundtime=currenttime-ptr->startingtime;
ptr=ptr->link;
chip=chip+1;
break;
}
}
}
}
ptr=head;
while(ptr->link!=head)
{
ptr=ptr->link;
}
ptr->link=NULL;
ptr=head;
totalwait=0;
totalturn=0;
while(ptr!=NULL)
{
printf("\n The Process ID=%d",ptr->ProcessID);
printf("\nThe Waiting Time=%d",ptr->waitingtime);
printf("\nTurn Around TIme=%d",ptr->turnaroundtime);
printf("\n Bust Time =",ptr->busttime);
totalwait=totalwait+ptr->waitingtime;
totalturn=totalturn+ptr->turnaroundtime;
ptr=ptr->link;
}
totalwait=totalwait/count;
totalturn=totalturn/count;
printf("Average Waiting Time= %d",totalturn);
printf("Averaga Turn Around Time=%d",totalturn);
}