当我尝试从队列中弹出时,它不会弹出为什么?

时间:2018-05-10 02:09:44

标签: c++11

我有以下代码,但pop()函数不起作用我不会 知道原因。

#include < iostream >
#include < fstream >
#include < sstream >
#include < string >
#include < queue >

    using namespace std;
int quantum;
struct process {
    string name;
    int arrival;
    int burst;
    int priority;
};

process parseProcess(string s)
    //parse the given string s to find the process information
    {
        process p;
        stringstream lineStream;
        lineStream.str(s);
        string item;
        getline(lineStream, item, '$');
        p.name = item;
        getline(lineStream, item, '$');
        p.arrival = stoi(item);
        getline(lineStream, item, '$');
        p.burst = stoi(item);
        getline(lineStream, item, '$');
        p.priority = stoi(item);
        cout <<
            p.name << "\t" << p.arrival << "\t" << p.burst << "\t" << p.priority << "\t" << endl;
        return p;
    }
void second_write(queue < process > s, int n, int quantum) {
    int * burst_Time = new int[n], total = 0,
        total_turn_arround = 0;
    float avgwaiting_time = 0, avgturn_arround =
        0;
    int * remaining_burst_time = new int[n];
    int * waitting_time = new
    int[n];
    int * turn_arround_time = new int[n]; //now queue doesn't pop
    Why ? ? ? ? ? process temp = s.front();
    process p;
    queue < process > qtemp;
    for (int i = 0; i < n; i++) {
        p.name = temp.name;
        p.arrival = temp.arrival;
        p.burst = temp.burst;
        burst_Time[i] = p.burst;
        p.priority = temp.priority; * * s.pop(); * * qtemp.push(p);
        cout
            << temp.name << "\t" << temp.arrival << "\t" << temp.burst << "\t" <<
            temp.priority << endl;
    }
    for (int i = 0; i < n; i++) {
        remaining_burst_time[i] = burst_Time[i];

    }
    while (1) {
        bool finished = true;
        for (int i = 0; i < n; i++) {
            if (remaining_burst_time[i] > 0) {
                finished = false;
                if (remaining_burst_time[i] > quantum) {
                    total += quantum;
                    remaining_burst_time[i] -= quantum;
                } else {
                    total += remaining_burst_time[i];
                    waitting_time[i] = total - burst_Time[i];
                    remaining_burst_time[i] = 0;
                }
            }
        }
        if (finished == true) break;
    }
    for (int i = 0; i < n; i++) {
        turn_arround_time[i] = burst_Time[i] - waitting_time[i];
    }
    for (int i = 0; i < n; i++) {
        total += waitting_time[i];
        total_turn_arround += turn_arround_time[i];
    }
    avgturn_arround =
        total_turn_arround / n;
    avgwaiting_time = total / n;
    int w = 0;
    while (!qtemp.empty()) {
        process temp2 = qtemp.front();
        qtemp.pop();
    }

}

int main() //it takes two arguments 1:inputFile name,
2: outputFile name {
    string fileName;
    cout << "enter file name " <<
        endl;
    cin >> fileName;
    cout << "Enter quantum";
    cin >> quantum;
    ifstream infile(fileName);
    string line;
    queue < process > q;
    while (getline(infile, line)) {
        process p = parseProcess(line);
        q.push(p);
    }
    int Length = q.size();
    second_write(q, Length, quantum);

    /*Your code must be written here in order to sort the processes in
the queue in terms of the chosen cpu scheduling algorithm.     Your code
also needs to calcualte average wating time and average turnarround
time.     Finally your code needs to print the Gantt chart, waiting time
for each process and the average waiting time and the average
turnaround time on the screen     */

    return 0;
}

0 个答案:

没有答案