zoukankan      html  css  js  c++  java
  • 链表——尾插法

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <malloc.h>
     4 typedef struct student
     5 {
     6     int num;
     7     float socre;
     8     struct student *next;
     9 }Student;
    10 Student *creatlist(void)
    11 {
    12     Student *head,*pt;
    13     head=pt=(Student *)malloc(sizeof(Student));
    14     pt = head;
    15     head->next=NULL;
    16     Student *cur=(Student *)malloc(sizeof(Student));
    17     int num;float socre;
    18     scanf("%d,%f",&num,&socre);
    19     while(num)
    20     {
    21         cur=(Student *)malloc(sizeof(Student));
    22         cur->num=num;
    23         cur->socre=socre;
    24 
    25         pt->next  = cur;
    26         cur->next = NULL;
    27         pt=cur;
    28 
    29         scanf("%d,%f",&num,&socre);
    30     }
    31     return head;
    32 }
    33 int main()
    34 {
    35     Student *head=creatlist();
    36     head=head->next;
    37     while(head)
    38     {
    39 
    40         printf("num:%d,socre:%.f
    ",head->num,head->socre);
    41         head=head->next;
    42             
    43     }
    44     system("pause");
    45 }
  • 相关阅读:
    Hibernate使用笔记
    svn树冲突的解决方法
    SVN 清理失败的解决方法
    类的实现
    lua元表
    lua中table的常用方法
    C/C++作用域运算符::
    Cocos2d-x Lua 学习
    Lua学习
    吾 三十而望
  • 原文地址:https://www.cnblogs.com/huxiaobai/p/10199913.html
Copyright © 2011-2022 走看看