c - 我在 C 的链表中有问题(第一个节点为空)
问题描述
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。但是,它没有。我不知道哪个部分有错误...
解决方案
推荐阅读
- javascript - webdriverio测试可以在Unix上执行吗
- android - 无法解析 android 应用程序模块的
- python - Web3-Py:Nonce 事务覆盖问题
- javascript - Tailwind.min.css 在我的 Nuxt 应用程序中覆盖 tailwind.css
- mysql - 如何在我的组合框 vb.net 上使用月份过滤我的表格
- python - Python - 如何过滤数据框以仅保留一种产品的订单号?
- sql - 在 SQL 中将不同的日期格式转换为相同的日期格式?
- node.js - 在 Ubuntu 上用 Wine 运行节点
- javascript - 是什么导致此错误不断出现以及如何防止它继续发生
- database - 我如何知道数据是否在 iotdb 中刷新