• 链表链表...神奇的链表


    #include<stdio.h>
    #include<math.h>
    #include<algorithm>
    #include<string.h>
    #include<stdlib.h>
    #include<malloc.h>
    #define len sizeof(struct student)
    using namespace std;
    struct student
    {
        long num;
        float score;
        struct student *next;                 //声明一个指针变量  其中的    这个用structure student 定义   用next  储存  地址...........
    };
    using namespace std;
    int n;
    struct student *creat()                  //开辟一个新节点,
    {
        struct student *p1,*p2,*head;
        n=0;
        p1=p2=(struct student *)malloc(len);   //开辟一个长度为  len的 空间    用强制转换类型  获得它的首地址.....
        scanf("%ld%f",&p1->num,&p1->score);    //
        head=NULL;                             //
        while(p1->num!=0)                      //  约定学好不为0....
        {
            n++;
            if(n==1)                          //这是第一个节点  所以
                head=p1;                      // 让head   记录下来头结点的地址....
            else
                p2->next=p1;                  //                        //让上一次开辟的  next部分储存起来  刚才开辟的   p1的地址.... 
            p2=p1;                           //  p2 和head  都和p1相同....                       //将刚才开辟的 空间的首地址  赋予p2       (方便下一次又开辟的空间的首地址  向 刚才开辟的位置存放....)
            p1=(struct student *)malloc(len);//在此开辟一个新空间  p1  从原来的地址变成了现在的地址........
            scanf("%ld    %f",&p1->num,&p1->score);  //然后就要返回检查学号了.    
        }
        p2->next=NULL;
        return head;
    }
    void print(struct student *head)
    {
        struct student *p;
        p=head;
        if(head!=NULL)
        {
            do
            {
                printf("%ld%5.1f
    ",p->num,p->score);
                p=p->next;
            }while(p!=NULL);
        }
    }
    void main()
    {
        struct student *head;
        head=creat();
        print(head);
    }
  • 相关阅读:
    手机的基本功能测试情景模式
    C#.net技术内幕04集合
    .net 发送电子邮件
    SQL:select case when(转)
    《 C#技术内幕》学习01IDisposable
    C#.net技术内幕03字符串
    点击确定后页面跳转
    SQL注入式攻击
    C#.NET技术内幕 02表达式
    window xp自带的功能之繁体字
  • 原文地址:https://www.cnblogs.com/A-FM/p/5049532.html
Copyright © 2020-2023  润新知