Linked List 指的是一群资料存在于不连续的记忆体空间~
其中每个节点包含~ 资料 及 指标(指向下一个节点的地址)~
学习目标: Singly Linked List概念及实务
学习难度: ☆☆☆
#include <iostream>using namespace std;struct Node //节点构造{ int value; Node *next;};void print(Node* node) //印出节点{ while (node != NULL) { cout << node->value << " "; node = node->next; }}int main(){ Node* first=new Node; //实体化第1个节点~ Node* second=new Node; //实体化第2个节点~ Node* third=new Node; //实体化第3个节点~ first->next=second; //第1个节点的指标指向第2个节点~ first->value=5; //第1个节点的值存5~ second->value=10; //第2个节点的值存10~ second->next=third; //第2个节点的指标指向第3个节点~ third->value=15; //第3个节点的值存15~ third->next=NULL; //第3个节点的指标指向NULL~ print(first); //印出第1个节点~ return 0;}
参考资料:
https://www.geeksforgeeks.org/data-structures/linked-list/