💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[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); } ```