[C] Linked list

  • 起始:指向鏈結串列第一個節點的指標
  • 鏈結串列的節點
  • 當前節點的資料
  • 下一個節點的地址
  • 結尾:最後一個節點連接的地址寫「NULL」,表示鏈結串列結束。
typedef struct node {
int val;
struct node* next;
} Node;
Node* create_list(int arr[], int len){
if(!arr || len == 0)
return NULL;

Node *head, *tail;
for(int i=0; i<len; i++){
//create node
Node* curr = (Node*)malloc(sizeof(Node));
curr->val = arr[i];
curr->next = NULL;
//if it's first new node
if(i == 0){
head = curr;
tail = curr;
tail->next = curr;
tail = tail->next;

return head;
void print_list(Node* head){
Node* p = head;
printf("%d ", p->val);
p = p->next;
void delete_list(Node* head){
Node* tmp = head;
head = head->next;



Hi I am Samuel

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store