合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
[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); } ```