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;
    }

  • 相关阅读:
    园 首页 新随笔 联系 管理 订阅 订阅 RTSP协议转换RTMP直播协议
    sequence diagram
    Model Binding
    asp.net mvc
    系统日志和异常的处理①
    随机森林之oob error 估计
    Extjs相关知识点梳理
    Extjs报错处理
    webbrowser在html中写入内容并添加js
    tcpdump一个命令的剖析
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3258146.html
Copyright © 2011-2022 走看看