zoukankan      html  css  js  c++  java
  • 数据结构 单向动态链表的建立和输出

    #include<stdio.h>
    #include<stdlib.h>
    struct student{
      long int num;//学号
      float score;//成绩
      struct student*next;//指向下一个学生
      };
      int n=0;//有n个学生数据
    
      /*创建链表函数*/
      struct student* creat()
      {
          struct student *p1,*p2,*head;
          p2=p1=(struct student*)malloc(sizeof(struct student));//创建一个!!动态存储空间
          printf("please enter the first student:\n");
          scanf("%ld,%f",&p1->num,&p1->score);
          head=NULL;
          while(p1->num!=0)
          {
             n=n+1;
             if(n==1)head=p1;//头指针指向第一个数据
             else p2->next=p1;
             p2=p1;
             p1=(struct student*)malloc(sizeof(struct student));//开辟动态存储区
             scanf("%ld,%f",&p1->num,&p1->score);
          }
          p2->next=NULL;
          return head;
      }
      /*输出函数*/
     void print(struct student *head)
      {
          struct student *p1;
          p1=head;
          while(p1->num!=0)
          {
             printf("\nnum:%ld,score:%f",p1->num,p1->score);
             p1=p1->next;
          }
    
      }
      void main()
      {
         struct student *head;
         head=creat();
         printf("plese printf the num and score\n");
         print(head);
      } 
    数据结构要把我折磨疯了,视频我已经看了四五遍了,自己写代码还是有问题。。很崩溃。慢慢来。!
    结构体创建和结构体指针,得到了提高。函数调用,该调用哪个参数,返回值应该是哪个变量,很重要!
    关于scanf,键盘输入时,要与scanf里面格式要一模一样,空格都空格,用逗号时记得运行界面输入法转为英文!!!!

  • 相关阅读:
    二叉查找树
    Rust更换Crates源
    Raft共识算法
    Session
    可以编写代码的代码:代码生成的利与弊
    引用和自包含令牌(Reference Tokens and Introspection)
    认证授权-学习笔记1-OAuth 2.0
    spring security原理-学习笔记2-核心组件
    spring security原理-学习笔记1-整体概览
    零拷贝Zero copy-linux and java
  • 原文地址:https://www.cnblogs.com/sunmarvell/p/5984117.html
Copyright © 2011-2022 走看看