C 中的鏈結串列是一種動態資料結構,由一系列節點組成,其中每個節點包含資料和指向序列中下一個節點的指標(或引用)。與陣列不同,鏈結串列不會將元素儲存在連續的記憶體位置,從而實現更靈活的記憶體管理。
typedef struct node {
int val;
struct node *next;
} node_t;
typedef struct list {
node_t *head;
node_t *tail;
} list_t
void InsertatLast(list *l, int x) {
node_t * temp;
temp = (node_t * ) malloc(sizeof(node_t));
temp -> val = x;
temp -> next = NULL;
if (head == NULL) {
l->head = temp;
l->tail = temp;
} else {
l->tail -> next = temp;
l->tail = tail -> next;
}
}