调度算法实现C ++

时间:2013-04-22 19:48:25

标签: c++

我正在尝试编写CLOOK调度算法,我对如何继续前进有点遗憾。这就是我所拥有的

 queue<int> workQ;
int headPosition;
int temp;
int cyl;
cout << "Enter the number of cylinders: ";
cin >> cyl;
cout << "Please enter the head Position: " ;
cin >> headPosition;
cout << "Enter the request: "; 
    while(true)
    {
        cin >> temp;

        //Enter a '0' to signal the end of inputing request
        if(temp == 0)
        {
            break;
        }
        //Will implement check later to make sure the request is not greater than the number of cylinder        
        workQ.push(temp);
    }

    //Print content of Queue AND put into a vector
    queue<int> tempQ;
    vector<int>request;

        tempQ = workQ;
    while(!tempQ.empty())
    {
        cout << tempQ.front() << " ";
        //Put in vector for easier use
        request.push_back(tempQ.front());

        tempQ.pop();
    }

    cout << endl;
    queue<int> clook; // used to hold the order of the request after scheduling is complete

    //starting the CLOOK algorithm with the head set at 50 by user
    //for(int i = 0 ; i < request.size() ; i++)
    //{}

    int max;
    int min;
            //I didnt include the insertion Sort code but it works fine
    insertionSort(request, max, min);
    cout << max << endl;
    cout << min << endl;

    while(!request.empty())

        for(int i = 0 ; i < request.size(); i++)
        {
          // I am lost on how to go forward here!!

头部位置为50,气缸数为200。 工作要求如下[95,180,34,119,11,123,62,64]并进行了分类 我得到了[11,34,62,64,95,119,123,180]。我基本上想要开始 50表示CLOOK调度应服务34,11并跳转到180, 然后123,119,95,64,62(同时跟踪头部位置)

        }
    }

1 个答案:

答案 0 :(得分:0)

网上有十几种可用的实现,只是google它们。 例如http://ashbeecode.blogspot.ru/2011/05/c-look-disk-scheduling-algorithm.html