#include <stdio.h>
#include <stdlib.h>
// 链表节点结构体
struct Node {
int data;
struct Node* next;
};
// 创建新节点
struct Node* create_node(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->next = NULL;
return node;
}
int main() {
struct Node* head = create_node(1);
head->next = create_node(2);
head->next->next = create_node(3);
// 遍历链表
for (struct Node* p = head; p != NULL; p = p->next) {
printf("%d ", p->data);
}
printf("\n");
return 0;
}
关键特性:
#define、#include等进行文本替换malloc/free)