<style> .reveal .slides { text-align: left; } </style> ## Linked list Linked list(連結串列)是一種常見的資料結構,其使用node(節點)來記錄、表示、儲存資料(data),並利用每個node中的pointer指向下一個node,藉此將多個node串連起來,形成Linked list,並以NULL來代表Linked list的終點。 ![](https://i.imgur.com/J5gY8a5.png) ---- ![](https://i.imgur.com/KcG0PvL.png) * Data * Pointer * Address ---- 建立節點 : 利用 **struct** ```c++= #include<bits/stdc++.h> using namespace std; struct node{ int data; struct node *next = NULL; }; typedef struct node Node; int main() { ... } ``` ---- ![](https://i.imgur.com/KcG0PvL.png) ```c++= int main() { Node Node1, Node2, Node3; Node *first = &Node1; Node1.data = 7; Node1.next = &Node2; Node2.data = 3; Node2.next = &Node3; Node3.data = 14; } ``` ---- 函式 - PrintList : 全整個 Linked list 的 node 都 print 出來。 ```c++= void PrintList(Node *first) { Node *cur = first; while(cur != NULL) { cout << cur->data << " "; cur = cur->next; } } ``` ----
{"metaMigratedAt":"2023-06-17T16:32:52.758Z","metaMigratedFrom":"YAML","title":"程式設計培訓 - (10)","breaks":true,"slideOptions":"{\"theme\":\"solarized\",\"transition\":\"fade\"}","contributors":"[{\"id\":\"1dfd0d36-665c-414c-a3ba-995f194a8cb9\",\"add\":1166,\"del\":37}]"}
    118 views
   Owned this note