首页 > 其他 > 详细

--------------------------------浩强呀,,浩强....-----------------------------------这个 链表 代码 绝对有错,,,

时间:2015-12-15 22:31:38      阅读:289      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#define len sizeof(struct student)
struct student
{
    long num;
    float score;
    struct student *next;
};
using namespace std;
int n;
struct student *creat()
{
    struct student *p1,*p2,*head;
    n=0;
    p1=p2=(struct student *)malloc(len);   //开辟了一个 长度为  len的空间用强制转换类型    得到它的首地址...赋给p1...p2....
    scanf("%ld%f",&p1->num,&p1->score);    //在地址前面加上 地址运算符,,表示对这个地址的数据进行操作....
    head=NULL;                             //让头指针归零(没有什么卵用)......好像
    while(p1->num!=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;
}
void print(struct student head)
{
    struct student *p;
    p=head;
    if(head!=NULL)
    {
        do
        {
            print("%ld%f",p->num,p->score);
            p=p->next;
        }while(p!=NULL);
    }
}
void main()
{
    struct student *head;
    head=creat();
    print(head);
}

 ---------------------------输出代码-----------------------------------------------------

#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct student)
struct student
{
    long num;
    float score;
    struct student *next;
};
int n;
void print(struct student *head)
{
    struct student *p;
    p=head;
    if(head!=NULL)
    {
        do
        {
            printf("%ld%5.1f\n",p->num,p->score);
            p=p->next;
        }while(p!=NULL);
    }
}

 

--------------------------------浩强呀,,浩强....-----------------------------------这个 链表 代码 绝对有错,,,

原文:http://www.cnblogs.com/A-FM/p/5049532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!