链表——头标法插入

#include<stdio.h>
#include<stdlib.h>

struct Test
{
    int data;
    struct Test* next;
};
void printList(struct Test* head)
{
    struct Test* point;
    point = head;
    while(point != NULL)
    {
        printf("%d ",point->data);
        point = point->next;
    }
}
struct Test* InsertfromHead(struct Test* head,struct Test* new)
{//头标法插入
    if(head == NULL)
    {
        head = new;
       
    }else
    {
        new->next = head;
        head = new;
    }

    return head;

}
struct Test* CreadList(struct Test* head)
{//创建结点
    struct Test *new  = NULL;
    while(1)
    {
        new = (struct Test*)malloc(sizeof(struct Test));
        printf("Please you input data to list\n");
        scanf("%d",&(new->data));
        if(new->data == 0)
        {
            printf("you input 0 quit!\n");
            free(new);
            return head;
        }

           head = InsertfromHead(head,new);//将链表头,和要插入的数据传到头标法中
    }

}
int main()
{
    struct Test* head = NULL;

    head = CreadList(head);

    printList(head);

    return 0;
}
posted @   信号编程好难  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示