zoukankan      html  css  js  c++  java
  • ----------------------------------------链表链表!!!!------------------------------------------------------

    现在处于一种     指针不熟  链表不会的状态.....先附上一个  书上的输入代码再说.........汗,先存起来    去看指针吧.....

    #include<stdio.h>
    #include<stdlib.h>
    #define len sizeof(struct student)//宏定义  len为 结构体的长度
    struct student
    {
        long num;
        float score;
        struct student *next;
    };
    int n;
    struct student *creat()//  定义函数   此函数返回一个指向链表表头的  指针
    {
        struct student *head,*p1,*p2;     //   定义了三个 结构体指针       不占用空间9
        n=0;
        p1=p2=(struct student *)malloc(len);//将其函数值的返回值(内存上的地址强制转换为 struct student 的地址.....如果没有*的话p1和p2储存的就是(好像什么也是不,,汗))
          // 这里东西比较多....括号里面的是强制转换类型   这里相当于    给*p赋予了一个长度为len的空间 p1是指向这个空间的指针..
        scanf("%ld,%f",&p1->num,&p1->score);  //指针不熟悉....不怎么能看懂  日......得去再看看...
        head=NULL;                            //感觉这个并没有 什么卵用....  已经注释过了   好像并没有什么用 以后再补充  
        while(p1->num!=0)                     //约定 学号没有  为0的人   并且一次为结束.....    
        {
            n++;                              //总感觉      这几个指针 没有串联起来.......
            if(n==1)
                head=p1;
            else
                p2->next=p1;
            p2=p1;
            p1=(struct student *)malloc(len);
            scanf("%ld%f",&p1->num,&p1->score);
        }
        p2->next=NULL;
        return head;
    }
    int main()
    {
        struct student *pt;
        pt=creat();
        printf("%lf   %f",pt->num,pt->score);
        return 0;
    };
  • 相关阅读:
    python 编码问题
    关于网页划词翻译
    clang 编译 c++
    Java流(Stream)操作实例筛选、映射、查找匹配
    JAVA系列笔记十八之nohup实现后台运行程序
    VSCode汇总
    java jdk 国内下载镜像地址及安装
    LocalDate、LocalDateTime与timestamp、Date的转换
    List.sort()排序功能
    Java Array、List、Set互相转化
  • 原文地址:https://www.cnblogs.com/A-FM/p/5047190.html
Copyright © 2011-2022 走看看