多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## 链表创建 ``` #include <stdio.h> #include <stdlib.h> typedef struct node { int data; node* next; } node; node* create() { int i = 0; node* head, *tail, *next; int x = 0; head = (node*)malloc(sizeof(node)); while (1) { printf("Please input your data:\n"); scanf("%d", &x); if (x==0) break; tail = (node*) malloc(sizeof(node)); tail->data = x; if (++i == 1) { head->next = tail; //链表只有一个元素,添加到head后面 } else { next->next = tail;//链表元素个数>1,把元素链接到链表尾端 } next = tail; //next指向末尾 } tail->next = NULL; return head; } int main() { node* head = create(); printf("head: %p\n", head); } ```