SJF EL TRABAJO MAS CORTO PRIMERO

Integrantes: Alex Gonzaga
Cesar Montalvan

A continuación se presenta el código SJF realizado en c:

1. //////////////////////////////////////////////////////
2. /////// SJF EL TRABAJO MAS CORTO PRIMERO ///////
3. ////////////////////////////////////////////////////
4.
5.
6. # include
7. # include
8. # include
9.
10. struct node
11. { int process_no;
12. int btime;
13. struct node *link;
14. };
15.
16. void append(struct node **,int,int);
17. void display(struct node *,int);
18. void chart(struct node **);
19.
20. void main()
21. { clrscr();
22. struct node *p;
23. p = NULL;
24. int i=1,time;
25. char ans = ‘y’;
26. while(ans != ‘n’)
27. { printf(”\nEnter Burst Time For Process No. %d : “,i);
28. scanf(”%d”,&time);
29. append(&p,i,time);
30. printf(”Any More Process (Y/N) ? “);
31. ans = getche();
32. i++;
33. }
34. getch();
35. clrscr();
36. printf(”\nThe Order Of Execution Of Process For SJF Algorithm Will be :- “);
37. display(p,1);
38. getch();
39. printf(”\nThe Waiting Time Of Process For SJF Algorithm Will be :- “);
40. display(p,2);
41. getch();
42. chart(&p);
43. getch();
44.
45. }
46.
47. void append(struct node **q,int i,int time)
48. { struct node *r,*temp = *q;
49. r = (struct node *)malloc(sizeof(struct node));
50. r->process_no = i;
51. r->btime = time;
52.
53. if(*q==NULL || (*q)->btime > time)
54. { *q = r;
55. (*q)->link = temp;
56. }
57. else
58. {
59. while(temp != NULL)
60. { if(temp->btime link->btime > time || temp->link ==NULL))
61. { r->link = temp->link;
62. temp->link = r;
63. r->link = NULL;
64. }
65. temp = temp->link;
66. }
67. }
68. }
69.
70. void display(struct node *q,int kk)
71. { struct node *temp;
72. int wtime,avg=0,total = 0,count=0;
73. temp = q;
74. int i;
75. printf(”\n”);
76. printf(”\n\t\t%c”,218);
77. for(i=1;i<33;i++)
78. { if(i==17)
79. printf(”%c”,194);
80. else
81. printf(”%c”,196);
82. }
83. printf(”%c”,191);
84. if(kk==1)
85. { printf(”\n\t\t%c PROCESS NO. %c BURST TIME %c\n”,179,179,179);
86. }
87. if(kk==2)
88. { printf(”\n\t\t%c PROCESS NO. %c WAIT TIME %c\n”,179,179,179);
89. }
90. printf(”\t\t%c”,195);
91. for(i=1;iprocess_no,179,temp->btime,179);
103. }
104. if(kk==2)
105. { if(temp ==q) /* First Process In The Ready Queue */
106. { wtime = 0;
107. total+= temp->btime;
108. avg+=wtime;
109. }
110. else
111. { wtime = total;
112. total+= temp->btime;
113. avg +=wtime;
114. }
115.
116. printf(”\n\t\t%c %d. %c %3d %c”,179,temp->process_no,179,wtime,179);
117.
118. }
119. temp=temp->link;
120. }
121. printf(”\n\t\t%c”,192);
122. for(i=1;ibtime;
145. temp4 = temp4->link;
146. }
147. if(sumbtime) == 0)
158. { goto harsh;
159. }
160. for(i=-1;ibtime);i++)
161. { printf(” “);
162. }
163. k+=temp3->btime;
164. printf(”%d”,k);
165. harsh:
166. temp3=temp3->link;
167. }
168. printf(”\n”);
169. while( temp !=NULL)
170. { if(temp == *q)
171. {
172. printf(”%c%c”,218,196);
173. if((sfactor*temp->btime) == 0)
174. { goto last;
175. }
176.
177. for(i=-1;ibtime);i++)
178. { printf(”%c”,196);
179. }
180. if(temp->link != NULL)
181. { printf(”%c”,194);
182. }
183. else
184. { printf(”%c”,191);
185. }
186. }
187. else
188. { if((sfactor*temp->btime) == 0)
189. { goto last;
190. }
191. for(i=-1;ibtime);i++)
192. { printf(”%c”,196);
193. }
194. if(temp->link != NULL)
195. { printf(”%c”,194);
196. }
197. else
198. { printf(”%c”,191);
199. }
200. }
201. last:
202. temp = temp->link;
203.
204. }
205. printf(”\n”);
206. printf(”%c “,179);
207.
208. while(temp1 != NULL)
209. { if((sfactor*temp1->btime) == 0)
210. { goto last1;
211. }
212. for(i=0;ibtime);i++)
213. { if(i==int(sfactor*temp1->btime)/2)
214. { printf(”P%d”,temp1->process_no);
215. }
216. else
217. printf(” “);
218. }
219. printf(”%c”,179);
220. last1:
221. temp1 = temp1->link;
222.
223. }
224.
225. printf(”\n”);
226. while(temp2 !=NULL)
227. { if(temp2 == *q)
228. { printf(”%c%c”,192,196);
229. if((sfactor*temp2->btime) == 0)
230. { goto last2;
231. }
232. for(i=-1;ibtime);i++)
233. { printf(”%c”,196);
234. }
235. if(temp2->link != NULL)
236. { printf(”%c”,193);
237. }
238. else
239. { printf(”%c”,217);
240. }
241. }
242. else
243. { if((sfactor*temp2->btime) == 0)
244. { goto last2;
245. }
246. for(i=-1;ibtime);i++)
247. { printf(”%c”,196);
248. }
249. if(temp2->link != NULL)
250. { printf(”%c”,193);
251. }
252. else
253. { printf(”%c”,217);
254. }
255. }
256. last2:
257. temp2=temp2->link;
258.
259. }
260. }

Leave a Reply