zoukankan      html  css  js  c++  java
  • 链表链表...神奇的链表

    #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);
    }
  • 相关阅读:
    在AS/400上根据日期生成星期几
    如何删除含无效字符的文件
    在CL中使用SST或者SUBSTRING
    取网络属性
    如何在程序中获取系统ASP使用率等系统状态信息
    在CL中使用ELSE
    在CL中读一个文件
    如何在FTP命令行执行AS/400命令
    广告悬停功能
    关于Grouping, Rollup,cube,
  • 原文地址:https://www.cnblogs.com/A-FM/p/5049532.html
Copyright © 2011-2022 走看看