| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 383 人关注过本帖
标题:[求助]我有一些问题想请教你们.
只看楼主 加入收藏
中山DJ肥仔
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-4-20
收藏
 问题点数:0 回复次数:2 
[求助]我有一些问题想请教你们.

给定程序中已建立一个带有头结点的单向链表,链表中的各结点按结点数据域中的数据从小到大顺序链接。函数fun的功能是:把形参x的值放入一个新结点并插入到链表中,插入后各结点仍保持从小到大顺序排列。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h, int x)
{ SLIST *p, *q, *s;
s=(SLIST *)malloc(sizeof(SLIST));
/**********found**********/
s->data=___1___;
q=h;
p=h->next;
while(p!=NULL && x>p->data) {
/**********found**********/
q=___2___;
p=p->next;
}
s->next=p;
/**********found**********/
q->next=___3___;
}
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i<N; i++)
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
{ printf("\nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End\n");
}
}
main()
{ SLIST *head; int x;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("\nThe list before inserting:\n"); outlist(head);
printf("\nEnter a number : "); scanf("%d",&x);
fun(head,x);
printf("\nThe list after inserting:\n"); outlist(head);
}





谁会就帮帮我啊..
搜索更多相关主题的帖子: include 文件夹 下划线 源程序 
2007-04-20 18:30
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 
OK没有问题了:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h, int x)
{ SLIST *p, *q, *s;
s=(SLIST *)malloc(sizeof(SLIST));
/**********found**********/
s->data=x;
q=h;
p=h->next;
while(p!=NULL && x>p->data) {
/**********found**********/
q=s;
p=p->next;
}
s->next=p;
/**********found**********/
q->next=s;
}
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q;
int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i<N; i++)
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
{ printf("\nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End\n");
}
}
int main(void)
{ SLIST *head; int x;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("\nThe list before inserting:\n"); outlist(head);
printf("\nEnter a number : "); scanf("%d",&x);
fun(head,x);
printf("\nThe list after inserting:\n"); outlist(head);
return 0;
}

~~我的明天我知道~~
2007-04-20 18:53
中山DJ肥仔
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-4-20
收藏
得分:0 

谢谢.

2007-04-20 20:14
快速回复:[求助]我有一些问题想请教你们.
数据加载中...
 
   



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

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