dimanche 1 novembre 2015

C# IF statement

        for (int k = 0; k < proc.Count; k++){
            for (int i = k + 1; i < proc.Count; i++){
                if (proc[k].arrivalTime >= proc[i].arrivalTime && proc[k].priority >= proc[i].priority && proc[k].brust > proc[i].brust){ 
                    temp = proc[i];
                    proc[i] = proc[k];
                    proc[k] = temp;
                }
            }
        }

Input

Process Arrival Brust Priority P0 0 10 5 P1 1 3 1 P2 1 2 1 P3 5 1 5 P4 5 8 2

I want to sort these processes following these rules 1) If the process arrived alone it'll work no matter what. 2) If 2 processes arrived in the same time, we gonna check the priority if the first one has higher priority(lower number) it'll work first, and if they have the same priority we gonna let the one who has lower Brust work first.

There's problem with last 2 processes where's the problem?

P3    5    1     5
P4    5    8     2

process 4 should work because it has higher priority

Aucun commentaire:

Enregistrer un commentaire