| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1445 人关注过本帖
标题:链表问题
取消只看楼主 加入收藏
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
结帖率:95.37%
收藏
已结贴  问题点数:20 回复次数:5 
链表问题
#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct student)
struct student
{
    int num;
    int socre;
    struct student *next;   
};
int n;
int main()
{
      struct student *pt;
      struct student *create();               //这里人如果写形参怎么写
      void *print(struct student *);
      pt=create();
      print(pt);
      return 0;
}
struct student *create()
{
    n=0;
    struct student *head;
    struct student *p1,*p2;
    p1=p2=(struct student*)malloc(len);
    scanf("%d%d",&p1->num,&p1->socre);
    head=NULL;
    while(p1->num!=0)
    {
        n++;
        if(n==1)
          head=p1;
        else
          p2->next=p1;
        p2=p1;
        p1=(struct student*)malloc(len);
        scanf("%d%d",&p1->num,&p1->socre);
    }
    p2->next=NULL;
    return head;
}
void print(struct student *p)
{
    struct student *p3;
    p3=p;
    do
    {
        printf("%d%d\n",p3->num,p3->socre);
    }while(p3!=NULL);
}

[此贴子已经被作者于2017-6-6 21:37编辑过]

搜索更多相关主题的帖子: include return create 
2017-06-06 21:31
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
收藏
得分:0 
回复 2楼 renkejun1942
struct student *del(struct student*,long);
 struct student *insert(struct student*,struct student*);
为什么不像这几个函数一样加 形参?(链表确实是个好东西 太难了
2017-06-06 22:09
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
收藏
得分:0 
回复 4楼 renkejun1942
我还不是太理解 那个 再麻烦说下 哪里不同呗
2017-06-06 22:20
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
收藏
得分:0 
回复 6楼 renkejun1942
恩 好的 谢谢你。。我们写的题规定的创建动态链表插入删除等都要定义函数来写。但是这几个问题老师讲的不过十来分钟就过了,一直处于懵懂状态
2017-06-06 22:39
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
收藏
得分:0 
struct student *insert(struct student*,struct student*);
 printf("please input insert number:\n");
      scanf("%d%d",&stu.num,&stu.socre);          //
      head=insert(head,&stu);
      print(head);

struct student *insert(struct student *head,struct student *stud)
{
    struct student *p0,*p1,*p2;
    p1=head;
    p0=stud;
    if(head==NULL)         //
    {
        head=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num>p1->num)&&(p1->next!=NULL))            //
        {
            p2=p1;//
            p1=p1->next; //
        }
        if(p0->num<=p1->num)//
        {
            if(head==p1)
               head=p0;
            else
               p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
        n++;
        return head;
    }
}


各位帮忙解释下上面几注释的地方呗。。。
2017-06-06 23:09
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
收藏
得分:0 
回复 9楼 炎天
恩 好的谢谢你。
2017-06-07 22:42
快速回复:链表问题
数据加载中...
 
   



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

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