gpt4 book ai didi

c - 访问链表节点中的位数组

转载 作者:太空宇宙 更新时间:2023-11-04 08:57:14 25 4
gpt4 key购买 nike

我有一个这样定义的链表:

typdef struct _seg
{
int bits[256]; // # of bits in bits[] array = 256

struct _seg *next; // link to the next segment
} seg;

我想知道如何访问此列表的每个节点内的位数组。如果它是一个常规的 int 变量并且该列表称为 p,我可以只执行 p->bits = 13;。但在这种情况下,我不知道如何访问和修改列表。有人可以帮帮我吗?

附言(不那么重要)有谁知道 seg; 最后做了什么?

最佳答案

要访问列表中的节点,您必须使用循环来迭代所有元素:

seg* p = createList();

seg* current = p; // start at first element
while( current != NULL ){
for( int i=0; i<256; i++ ) {
current->bits[i] = 13; // modify bits inside
}
current = current->next; // go to next element in the list
}

关于c - 访问链表节点中的位数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16360452/

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