struct process {
int id;
struct process * prev;
struct process * next;
}
struct process * ready = NULL;
struct process * running;
int main() {
struct process * curr = NULL;
curr = ready;
while (curr != NULL) {
curr = curr - > next;
}
struct process * tmp = (struct process * ) malloc(sizeof(struct process));
//running->id=1 !!!
tmp = running;
printf("%d", tmp - > id); //it prints 1
tmp - > next = NULL;
curr = tmp;
printf("%d", curr - > id); //it prints 1
}
我做了这样的链表。在while循环之前,* ready为空。我认为curr指向就绪,我将运行的ID复制到curr的第一个节点的ID。因此,我认为ready的ID将为1。但是,事实并非如此。我不知道哪一部分有错误...