└── cscan /cscan: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0; 5 | clrscr(); 6 | printf("enter the no of tracks to be traveresed"); 7 | scanf("%d'",&n); 8 | printf("enter the position of head"); 9 | scanf("%d",&h); 10 | t[0]=0;t[1]=h; 11 | printf("enter total tracks"); 12 | scanf("%d",&tot); 13 | t[2]=tot-1; 14 | printf("enter the tracks"); 15 | for(i=3;i<=n+2;i++) 16 | scanf("%d",&t[i]); 17 | for(i=0;i<=n+2;i++) 18 | for(j=0;j<=(n+2)-i-1;j++) 19 | if(t[j]>t[j+1]) 20 | { 21 | temp=t[j]; 22 | t[j]=t[j+1]; 23 | t[j+1]=temp; 24 | } 25 | for(i=0;i<=n+2;i++) 26 | if(t[i]==h) 27 | j=i;break; 28 | p=0; 29 | while(t[j]!=tot-1) 30 | { 31 | } 32 | atr[p]=t[j]; 33 | j++; 34 | p++; 35 | atr[p]=t[j]; 36 | p++; 37 | i=0; 38 | while(p!=(n+3) && t[i]!=t[h]) 39 | { 40 | } 41 | atr[p]=t[i]; 42 | i++; 43 | p++; 44 | for(j=0;jatr[j+1]) 47 | d[j]=atr[j]-atr[j+1]; 48 | else 49 | d[j]=atr[j+1]-atr[j]; 50 | sum+=d[j]; 51 | } 52 | printf("total header movements%d",sum); 53 | printf("avg is %f",(float)sum/n); 54 | getch(); 55 | } 56 | --------------------------------------------------------------------------------