Sunday, 24 June 2012

c++ program to count total number of head movement using Shortest seek job first(SSJF) scheduling algorithm.

#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>

int main()
{
int n;
cout<<"enter your queue size:";
cin>>n;
int ub,lb=0;
cout<<"Enter your upper bound:";
cin>>ub;
int queue[3];
int head;



cout<<"Enter your head:";
cin>>head;
int minindex;
int temp,len=0,i,j,rem[3],prev=ub,current=0,qsize=n,rsize=n;
    for(i=0;i<n;i++)
    {
        cout<<"enter value for queue:";
        cin>>queue[i];
        rem[i]=i;
    }
    current=head;
    for(i=0;i<n;i++)
    {
        prev=ub;
        minindex=0;
        for(j=0;j<rsize;j++)
            {   
               
                temp=abs(current-queue[rem[j]]);
                if(temp<prev)
                {
                    minindex=j;
                    prev=temp;
                }

            }
        len=len+prev;
        cout<<endl<<len<<endl;
        current=queue[rem[minindex]];
        for(j=minindex;j<rsize-1;j++)
        {
            rem[j]=rem[j+1];
        }
        rsize=rsize-1;

    }
    cout<<endl<<"total ::";
    cout<<len;   
return 0;
}


Various Process Scheduling Algorithms:

Various Page Replacement Algorithms:

Various Disk Head Movement Counting Algorithms: