问题 填空题

给定程序MODI1.C是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
文件MODI1.C内容如下:
#include<stdio.h>
#include<stdlib.h>
typedef struet aa
int data;
struet aa *next;
NODE;
int fun( NODE *h)
int max=-1:
NODE *p;
/**********found**********/
p=h;
while(p)t
if(p->data>max)max=p->data;
/**********found**********/
p=h->next;

return max;

void outresult(int s,FILE *pf)fprintf(pf,"\nThe max in link: %d\n",s);
NODE *creatlink(int n,int m)
NODE *h,*p,*s;
int i;
h=p=(NODE *)malloc(sizeof(NODE));
h->data=9999;
for(i=1;i<=n;i++)
S=(NODE$)malloe(sizeof(NODE));
s->data=rand( )%m;
s->next=p->next;
p->next=s;
p=p->next;

p->next=NULL;
return h;

void outlink(NODE *h,FILE *pf)
NODE *p;
p=h->next;
fprintf(pf,"\nTHE LIST: \n\n HEAD");
while(p)
fprintf(pf,"->%d",p->data);
p=p->next;

fprintf(pf,"\n");

void main()
NODE *head: int m;
head=ereatlink(12,100);
outlink(head,stdout);
m=fun(head);
printf("\nTHE RESULT: \n"):
outresult(m,stdout);

答案

参考答案:第1处:将“p=h;”改为“p=h->next;”。
第2处:将“p=h->next;”改为“p=p->next;”。

解析: 题目要求求出链表结点中数据域的最大值,所以需要对链表进行遍历,取出每一个结点的数据域与变量max进行比较,比max大则对max重新赋值。对链表进行遍历通常会引入一个结构体指针p来完成,而指针h存放了头结点的地址,所以编程时不会对h的值进行改变。由于是带头结点的链表,第一个结点没有数据域,所以第1处错误是一个赋值的错误,对p赋初值应该是h->next。循环中利用指针p对链表进行遍历,当取出当前结点的数据进行比较处理后,指针p应该往后移动,指向下一个结点,所以第2处应该改为“p=p->next;”。
[归纳总结] 在链表处理过程中,常见错误有:
(1)指针赋值错误。尤其要注意带头结点的链表和不带头结点的链表,在对指针p赋初值时有一点细微的区别。
如果是带头结点的链表,对p赋初值的语句应该是:p=h->next;对于不带头结点的链表,对p赋初值的语句应该是:p=h;。
对链表进行遍历需要利用循环。在循环过程中,让指针p指向下一个结点,常用语句为:p=p->next;。
(2)链表头结点地址错误。链表处理过程中,头结点的地址通常赋值给指针h,h的值不能发生改变,如果要对链表进行访问,一般会引入一个指针p进行循环。

阅读理解

The year 2009 is the Year of Ox. The ox is a representative of the fanning culture of China. In the farming economy (经济), oxen are the major animals pulling plows (犁).

Of course, the good of oxen is not limited to plowing.  In fact, they are seen as "boats on land" for their ability to carry loads. Besides, the whole body of an ox is full of treasures. Their meat and milk are food full of nutrition, and their skin can be used to make clothes and shoes. With all these qualities, oxen are regarded as generous creatures.

In the past, oxen played an important role in the spiritual life of the Chinese. Even today, oxen still play a special part in some folk activities. For example, some people who1ire in southwest China will cook cattle bone soup and share it among family members when holding the ceremony for children who reach 13. They believe that the cattle bone soup represents the blood relationship among family members. In order to express their love for oxen, people in some other areas will run to shake off diseases on the 16th day of the first month by the lunar calendar (农历), and during their run they will take their oxen along, which indicates they regard the creature as human.

Because of the contribution of oxen in their lives, the Chinese people are very grateful to the animal. In addition, the use of oxen in ceremonies and the thanks people owe to oxen help to develop various traditional customs, which becomes an important part of the folk culture of the Chinese nation.

小题1:The words "boats an land" underlined in Paragraph 2 refer to __

A.animals for taking goods

B.creatures for pulling plows

C.treasures of the folk culture

D.tools in the farming economy小题2:From the third paragraph, we know that __

A.oxen are no more important today than in the past

B.ceremonies are held when people cook cattle bone soup

C.oxen are treated as human in some areas of China

D.people run with oxen to shake off diseases every month小题3:Which of the following helps to develop traditional customs?

A.The special role of oxen in frowning.

B.People's respect and love for oxen.

C.The practical value of an ox's body.

D.The contribution of oxen to the economy.小题4:Why does the author write the text?

A.To stress the importance of oxen in farming.

B.To introduce the Chinese folk culture.

C.To describe how to celebrate the Year of Ox.

D.To explain how to develop agriculture with oxen.

单项选择题