# Linked list: Traverse the list

* 新增一個指向head的指針
* 當指針不指向NULL時
  * 指針 = 指針 -> next

```
void display(struct Node *first) {
    Node *list = first;
    while(list) {
        cout << list->data << " ";
        list = list->next;
    }
    cout << endl;
}
```

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LIZfYG3WqVkWWMmk0Nu%2F-LIZyXU1AfvaxukfUNLR%2Fbfb0f7ea-9826-4098-b170-8e2202264eb3.png?alt=media\&token=c687b6cb-64f3-40ff-a939-93a52a933396)

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LIZfYG3WqVkWWMmk0Nu%2F-LIZy_BCvzCMcNOtZLV4%2Fc524adff-c147-45eb-99d7-a4623345775f.png?alt=media\&token=7ccc138a-9aaf-44fd-982c-e2e8a319119c)
