zoukankan      html  css  js  c++  java
  • 链表的创建与插入练习

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

    typedef struct node
    {
        int  name[5];
        struct node *next;
        
    } student;

    struct node* creatList(int n)
    {
        int i=0;
        student *head,*p;
        head=(student*)malloc(sizeof(student));
        head->next=NULL;
        printf("请输入%d个数据,来创建链表 ",n);
        for(;i<n;i++)
        {
            p=(student*)malloc(sizeof(student));
            //printf("%p",p);
            scanf("%s",&(p->name));
            p->next=head->next;
            head->next=p;
        }
        return head;
    }
    void insertNode(student* node,int index)
    {
        student *newnode,* p=node->next;
        int n=0;
        while(p&& n<index)
        {
            p=p->next;
            n++;
        }
        newnode=(student*)malloc(sizeof(student));
        scanf("%s",&(newnode->name));
        newnode->next=p->next;
        p->next=newnode;

        if(!p)
        {
            return ;
        }

    }
    void printOn(student* head)
    {
        student* p=head->next;
        while(p)
        {
            printf("%s",p->name);
            p=p->next;
        }

    }
    int main()
    {

        student *p=creatList(5);
        printOn(p);
        return 0;
    }

  • 相关阅读:
    day14 多态与抽象
    day13 类的补充
    day12 继承
    第三周总结 类、对象、包
    day11 细节记忆
    Dapper使用
    修改SQL Server 中数据库的Collation
    Web API 输出文件缓存
    Sql从邮件中提取国家代码
    解决Nuget:https://api.nuget.org/v3/index.json 访问不了的问题
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3258146.html
Copyright © 2011-2022 走看看