0

我必须为一堂课制作一个循环调度程序。我最初创建了 3 个List<int>列表来表示进程 ID、它们的到达时间和它们的处理时间。我按照他们的到达时间对他们进行了分类。这些进程被分配了一个固定的时间量(我已经硬编码为 4),现在我想在它们上应用 RR 并在textBox表格中显示每个进程的序列顺序和它们的剩余时间。

我在这里找到了一种方法,但它在 java 中: https ://stackoverflow.com/questions/7544452/round-robin-cpu-scheduling-java-threads

我尝试将我的三个列表转换为链接中所示的对象列表,但基本上,到目前为止,我已经成功创建了一个代表进程的对象列表。在每个对象中,processname存储 , , arrivaltimebursttime这由一个名为 的类表示PCB

现在我创建了一个列表来添加一些进程:

public List<pcb> list = new List<pcb>(); // In place of ArrayList used in the 
                                         // example code in the link.

//For loop runs in which above 3 parameters are assigned values & then they're 
// added to list:

PCB pcb = new PCB(processname1, arrivaltime1, bursttime1);
list.Add(pcb);

但是如何搜索列表的每个值以找到一个项目并对其进行操作?假设我想访问并减少 4 bursttimeprocessname="P1"

这是 C# 中的错误数据结构吗?

4

1 回答 1

0
// To access the value:
int bursttime1 = list.FirstOrDefault(x => x.processname == "P1").bursttime;
// To change it:
list.FirstOrDefault(x => x.processname == "P1").bursttime -= 4;

如果您更喜欢遍历列表:

foreach (PCB pcb in list) {
    if (pcb.processname == "P1") {
        pcb.bursttime -= 4;
    }
}
于 2011-12-04T17:12:39.790 回答