| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 499 人关注过本帖
标题:程序运行结果有问题,帮忙看看。链表
只看楼主 加入收藏
陈威
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2009-10-18
结帖率:95%
收藏
已结贴  问题点数:10 回复次数:1 
程序运行结果有问题,帮忙看看。链表
#include "stdio.h"
#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)

struct student
{char num[6];
 char name[8];
 struct student *next;
};

struct student *creat(void)
{struct student *p1,*p2,*head;
 int n=0;
 p1=p2=(struct student *)malloc(LEN);
 head=NULL;
 printf("Input 0 to end.\n");
 printf("Input num,name:\n");
 scanf("%s,%s",p1->num,p1->name);
 while(p1!=NULL)
 {if(n==0)head=p1;
  else p2->next=p1;
  n++;
  p1=(struct student *)malloc(LEN);
  scanf("%s,%s",p1->num,p1->name);
  p2=p1;
 }
 p2->next=NULL;
 return(head);
}

void print(struct student *p)
{while(p!=NULL)
 {printf("%4s,%4s\n",p->num,p->name);
  p=p->next;
 }
}

main()
{struct student *ha,*hb,*p1,*p2,*p;
 ha=creat();
 hb=creat();
 print(ha);
 print(hb);
 p1=ha;
 /*delete*/
 while(p1!=NULL)
 {p2=hb;
  if(p2!=NULL&&strcmp(p2->num,p1->num)!=0)
  p2=p2->next;
  else
  {if(p1==ha)
      p1->next=ha;
   else
      p->next=p1->next;
  }
   p=p1;
   p1=p1->next;

 }
 print(ha);
    getch();
}
搜索更多相关主题的帖子: 运行 结果 链表 
2010-02-04 06:37
smallas
Rank: 2
等 级:论坛游民
帖 子:8
专家分:21
注 册:2010-2-3
收藏
得分:7 
我来看看 !
2010-02-04 15:26
快速回复:程序运行结果有问题,帮忙看看。链表
数据加载中...
 
   



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

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