[英]how to create a linked list inside a linked list in c
我想創建一個主列表,每個主列表元素都有另一個列表。
這就是我所做的
typedef struct smallList
{ char data;
struct smallList *next;
} small;
typedef struct bigList
{
int count;
char data;
struct bigList *next;
struct smallList *head;
} big;
但是如何從大列表中訪問小列表數據並將內容添加到小列表中。 任何幫助非常感謝。 謝謝....
因此,如果我們假設已經填充了這個結構,我們可以這樣做:
struct smallList *smallElem = NULL;
struct bigList *bigElem = NULL;
for (bigElem = your_big_list(); bigElem != NULL; bigElem = bigElem->next) {
// Do something with bigElem.
for (smallElem = bigElem->head; smallElem != NULL; smallElem = smallElem->next) {
// Do something with the smallElem.
// Note that we can still reference bigElem here as well.
}
}
如果p
指向bigList:
bigList -> head
是bigList指向的小列表。 (bigList -> head).data
是smallList包含的字符。 (bigList -> next -> head)
是bigList中的第二個smallList。 (bigList > head -> next)
是bigList的第一個smallList中的第二個元素。 獲取指向要修改的結構的指針后,其他所有內容都相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.