码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-12-15 22:33:08      阅读:221      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!