| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 410 人关注过本帖
标题:链表的郁闷问题
只看楼主 加入收藏
小林
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-9-7
收藏
 问题点数:0 回复次数:0 
链表的郁闷问题

#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
int scroe;
struct student *next;
};
main()
{
struct student *head,*p1,*p2,*p3,*head1,*p4,*p5,*p6,*p7,*p8,*p9;

/*输入第一个链表*/
head = p1 = (struct student*)malloc(sizeof(struct student));
head = NULL;
head -> next = p1;
printf("input date\n");
scanf("%d%d",&(p1 -> num),&(p1 ->scroe));
while((p1 -> num != 0)&&(p1 -> scroe != 0))
{
p2 =(struct student*)malloc(sizeof(struct student));
p1 -> next = p2;
p1 = p2;
scanf("%d%d",&(p1 -> num),&(p1 -> scroe));
}
p1 -> next = NULL;
printf("\n");
p6 = head -> next;
printf("%df",p6->scroe); /*如果不加这几话,下面代文号的printf出来的结果和加这几话会不同。请问这是为什么???win - tc下运行的

/*输入第二个链表*/
head1 = p4 = (struct student*)malloc(sizeof(struct student));
head1 = NULL;
head1 -> next = p4;
printf("input second date\n");
scanf("%d%d",&(p4 -> num),&(p4 -> scroe));

while((p4 -> num != 0)&&(p4 -> scroe != 0))
{
p5 = (struct student*)malloc(sizeof(struct student));
p4 -> next = p5;
p4 = p5;
scanf("%d%d",&(p4 -> num),&(p4 -> scroe));
}
p4 -> next =NULL;
printf("\n");


p7 = head1 -> next;
printf("%d %d",p6->scroe,p7->scroe); /*只是用来作为跟踪p6,p7的标记。

while((p7 -> num != 0)&&(p7 -> scroe != 0))
{
if(p6 -> scroe > p7 -> scroe)
{
p8 = (struct student*)malloc(sizeof(struct student));
p8 -> next = p6 -> next;
p6 -> next = p8;
p8 -> num = p7 -> num;
p8 -> scroe = p7 -> scroe;
p7 = p7 -> next;
p6 = p8 -> next;
}
}
p3 = head -> next;

/*打印出相加完的第一个链表*/
while((p3 -> num !=0)&&(p3 -> scroe != 0))
{
printf("%d %d",p3 ->num,p3 -> scroe);
p3 = p3->next;
printf("\n");
}
getch();
}

搜索更多相关主题的帖子: 链表 
2006-09-23 14:01
快速回复:链表的郁闷问题
数据加载中...
 
   



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

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