iT邦幫忙

2025 iThome 鐵人賽

DAY 9
0
自我挑戰組

c 語言與 python 的30天之旅系列 第 9

C 語言與資料結構之鏈結串列

  • 分享至 

  • xImage
  •  

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;
  }
}


上一篇
C 語言與封裝
系列文
c 語言與 python 的30天之旅9
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言