gpt4 book ai didi

c - 双向链表的一个节点中可以有多个元素吗?

转载 作者:行者123 更新时间:2023-11-30 15:54:44 24 4
gpt4 key购买 nike

我想知道是否可以在 C 中的双向链表的节点中插入多个元素。我需要它能够读取包含以下内容的文件:

00:00 67.7

00:01 67.6

00:02 67.7

00:03 67.6

00:04 67.6

00:05 67.3

00:06 67.4

并将前 4 个数字复制为 2 个整数,将第三个数字复制为 float 。我希望将这 3 个放入双向链表的一个节点中,以便稍后能够将它们与其他节点中的数字进行比较。我正在考虑类似这样的事情:

while (fscanf(ifp, "%d:%d %d.%d ", &hour, &min, &tempI, &tempD) != EOF) {

int dlist_ins_next(Dlist *list, DlistElmt *element1, *element2, *element3, const void *int1, *int2, *float);
}

最佳答案

由于您希望第三个作为浮点值,因此将扫描函数更改为:

fscanf(ifp, "%d:%d %f ", &hour, &min, &temp)

您应该将节点实现为结构:

struct node
{
int hour;
int min;
float temp;

struct node *next;
struct node *prev;
};

关于c - 双向链表的一个节点中可以有多个元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12766518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com