| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 823 人关注过本帖
标题:代码有点看不懂
只看楼主 加入收藏
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
结帖率:46.15%
收藏
已结贴  问题点数:20 回复次数:3 
代码有点看不懂
#include <iostream>
using namespace std;


struct student
{
    long number;
    float score;
    student * next;
};
student * head;
student * create()
{
    student * ps;
    student * pend;
    ps=new student;
    cin>>ps->number;cin>>ps->score;

    head=NULL;
    pend=ps;
    while(ps->number!=0)
    {
        if(head==NULL)
            head=ps;
        else
            pend->next=ps;
        pend=ps;
        ps=new student;
        cin>>ps->number>>ps->score;

    }
    pend->next=NULL;
    delete ps;
    return(head);
}
void showlist(student* head)
{
    cout<<"now the items of list are";
    while(head)
    {
        cout<<head->number<<","<<head->score<<endl;
        head=head->next;
    }
}
void main()
{
    showlist(create());
}
上面红色代码是一样的,有什么不同的作用吗?
搜索更多相关主题的帖子: 代码 
2009-10-18 16:13
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:4 
很常用的方法嘛~
第一个是要求输入,这样好作 while(ps->number!=0)的判断;
第二个则是while中的,要求循环输入,直到ps->number==0也就不满足while条件,从而退出.

2009-10-18 22:34
caolihui1008
Rank: 2
来 自:石家庄
等 级:论坛游民
帖 子:33
专家分:75
注 册:2009-10-19
收藏
得分:4 
就是建立一个链表嘛,哪里看不懂呢?
2009-10-19 09:20
zodiac207
Rank: 2
等 级:论坛游民
帖 子:16
专家分:38
注 册:2009-10-14
收藏
得分:4 
我想拿张约画画应该比较明了吧,如果看不明白的话
2009-10-19 15:32
快速回复:代码有点看不懂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015194 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved