#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int a[100],b[100],i,j,ls,n,ds,temp,ip,ip1;
int hm,mv,lv,min[100],max[100],flag=0;
char ch;
printf("Enter The Size of Disk: ");
scanf("%d",&ds);
printf("Enter The Length of String: ");
scanf("%d",&ls);
printf("\nEnter the String between 0 & %d:\n",ds);
for(i=1;i<=ls;i++)
{
scanf("%d",&a[i]);
if(a[i]<ds)
{
b[i]=a[i];
}
else
{
printf("\n\t*****Enter String is Larger Than Disk Size.*****\n");
printf("\t*****Please Hit The ENTER and do process again.*****\n\n");
exit(0);
}
}
printf("Enter The Initial Position: ");
scanf("%d",&ip);
if(ip<ds)
{
ip1=ip;
}
else
{
printf("\n\t*****Initial Position is Out Of Disk Space.*****\n ");
printf("\t*****Please Hit The ENTER and do process again.*****\n\n");
exit(0);
}
printf("\nPress L/l for left direction or lower value.");
printf("\nPress R/r/H/h for right direction or higher value.");
printf("\nEnter The Direction of scheduling.===================> ");
scanf("%s",&ch);
printf("\nSorted String is: " );
for(i=1;i<=ls;i++)
{
for(j=i+1;j<=ls;j++)
{
if(b[i]>=b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
printf("%d ",b[i]);
}
mv=b[1];
for(i=2;i<=ls;i++)
{
if(mv<b[i])
{
mv=b[i];
}
}
//printf("\nLarger value=%d",mv);
lv=b[1];
for(i=2;i<=ls;i++)
{
if(lv>b[i])
{
lv=b[i];
}
}
//printf("\nLowest value=%d\n\n",lv);
for(i=1;i<=ls;i++)
{
if(b[i]<ip1)
{
min[i]=b[i];
flag++;
}
else
{
max[i]=b[i];
}
}
//
//switch case statement
printf("\n==============================================================");
printf("\n\tMake Your Choice.");
printf("\n\tPress 1 for SCAN Disk sceduling Head Movement.");
printf("\n\tPress 2 for C-SCAN Disk sceduling Head Movement.");
printf("\n\tPress 3 for LOOK Disk sceduling Head Movement.");
printf("\n\tPress 4 for Exit.");
printf("\n\tEntered Choice===>\t");
scanf("%d",&n);
printf("\n==============================================================");
switch(n)
{
case 1:
if(ch=='l'||ch=='L')
{
hm=ip1+mv;
printf("\n\t\ttotal Head Movement=%d",hm);
}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ds-ip1)+(ds-lv));
printf("\n\t\ttotal Head Movement=%d",hm);
}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;
case 2:
if(ch=='l'||ch=='L')
{
hm=(ip1+ds+(ds-max[0]));
printf("\n\t\ttotal Head Movement=%d",hm);
}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ds-ip1)+(ds)+min[flag]);
printf("\n\t\ttotal Head Movement=%d",hm);
}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;
case 3:
if(ch=='l'||ch=='L')
{
hm=((mv-ip1)+(mv-lv));
printf("\n\t\ttotal Head Movement=%d",hm);
}
else if(ch=='r'||ch=='R'||ch=='h'||ch=='H')
{
hm=((ip1-lv)+(mv-lv));
printf("\n\t\ttotal Head Movement=%d",hm);
}
else
{
printf("\n\tEntered direction is invalid.\n");
exit(0);
}
break;
case 4:
exit(0);
break;
default:
printf("\n\n\t\t****Wrong Choice Selected by User***\n");
}
printf("\n\n\tCoded By-Ram Ranjeet Kumar\n\n");
return 0;
}
|
Ram Ranjeet Kumar- college-St.Xavier College Ranchi |