【发布时间】:2021-12-23 06:44:58
【问题描述】:
我想将一个元素添加到元素列表中。我的列表是一个结构,包含一个双精度、一个整数和一个指向下一个元素的指针。有人可以告诉我如何执行添加功能
#include <stdio.h>
#include <stdlib.h>
typedef struct Liste Liste;
struct Liste{
double c;
int n;
Liste* next; // pointe sur l'élément suivant
};
void Add(Liste array, Liste item) {
Liste* last = array.next;
while (last != NULL) {
last = last->next;
}
array.next = &item;
printf("%p\n", array.next);
}
int main(){
Liste array = {12.4, 4, NULL};
printf("%f\n", array.c);
Liste item = {15.4, 7, NULL};
Add(array, item);
printf("%p\n", array.next);
return 0;
}
【问题讨论】:
标签: c linked-list