-
Notifications
You must be signed in to change notification settings - Fork 12
/
_11c.diskcscan.c
54 lines (48 loc) · 860 Bytes
/
_11c.diskcscan.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
#include<stdio.h>
#include<stdlib.h>
void main()
{
int n,i,ind,j,t,h,q[20],count=0,low=0,max=199;
printf("Enter the length of queue:");
scanf("%d",&n);
printf("Enter the header:");
scanf("%d",&h);
n++;
printf("Enter the queue: ");
for(i=1;i<n;i++)
{
scanf("%d",&q[i]);
}
q[0]=h;
q[i++]=max;
n++;
for(i=0;i<n;i++)
{
for(j=0;j<n-1-i;j++)
{
if(q[j]>=q[j+1])
{
t=q[j];
q[j]=q[j+1];
q[j+1]=t;
}
}
}
for (i = 0; i < n; i += 1)
{
if(q[i]==h)
ind=i;
}
for(i=ind;i<n;i++)
{
printf("%d->",q[i]);
}
printf("%d->",low);
for(i=0;i<ind-1;i++)
{
printf("%d->",q[i]);
}
printf("%d",q[i]);
count=((q[n-1]-q[ind])+(q[n-1]-low)+(q[ind-1]-low));
printf("\nThe total disk movement is:%d\n",count);
}