问题 填空题

试题五
阅读以下说明和C语言函数,回答问题。
[说明]
已知包含头节点(不存储元素)的单链表的元素已经按照非递减方式排序,函数compress(NODE *head)的功能是去掉其中重复的元素,使得链表中的元素互不相同。
处理过程中,当元素重复出现时,保留元素第一次出现所在的节点。
图8-29(a)、(b)是经函数compress( )处理前后的链表结构示例图。


链表的节点类型定义如下:
typedef struct Node {
int data;
struct Node *next;
}NODE;
[C语言函数]
void compress(NODE *head)
{
NODE *ptr, *q;
ptr= (1) ; /*取得第一个元素节点的指针*/
while( (2) && ptr->next) {
q=ptr ->next;
while(q && (3) ){/*处理重复元素*/
(4) =q ->next;
free(q);
q=ptr->next;
}
(5) =ptr->next;
} /*end of while*/
} /*end of compress*/

答案

参考答案:ptr

解析: 本题考查的是对链表的查找、插入和删除等运算。要找到重复的元素并将其删除而使各元素互不相同。我们可以顺序遍历链表,比较逻辑上相邻的两个元素是否相同,如果相同则删除后一个元素,以此类推。代码如下: VOid Compress(NODE *head) { NODE *ptr, *q; ptr=head->next; /*取得第一个元素节点的指针*/ while(ptr && ptr->next) { q=ptr->next; while(q && ptr->data==q>data) { /*处理重复元素*/ ptr->next=q->next; free(q); q=ptr->next; } ptr=ptr->next; } /*end of while*/ } /*end of compress*/

选择题
填空题

Part 4


Questions 26-45


·Read the following passage and decide which answer best fits each space.
·For questions 26-45, mark one letter A, B, C or D on the Answer Sheet.
Participation (26) high school sports is not a constitutional right. (27) , it is a privilege, paid for by taxpayers, open to students who promise to (28) certain conduct requirements on and off the field. One of these promises is to (29) from using drugs. Drug use is a serious problem among high school students. Studies show that as many as 500, 000 high school students use muscle-pumping, life-destroying substances such as steroids. Many more use illegal drugs, (30) cause discipline problems and (31) the stage for lifelong (32) .
Drug testing works to (33) and identify use. That is why drug testing is required to compete in the Olympics, the National Collegiate Athletic Association and the National Football League. (34) drug testing was instituted by these organizations, use of performance- (35) drugs has been greatly reduced. We should want (36) in schools.
Indeed, many athletes (37) testing programs, and no wonder. Without testing, athletes have to choose between drug use and a competitive disadvantage (38) the field.
Those who challenge the need for drug testing may be forgetting (39) it is like be an adolescent. Peer pressure is enormous, and one of the few effective counter-weights is the fear of being caught. More importantly, once drug use is (40) , a school can (41) to the student before he or she gets addicted or arrested.
For 25 years, public schools (42) by federal judges and civil libertarians, with results everyone can see. It is time (43) decisions on how to run public schools locally (44) officials. There is nothing unconstitutional about asking those who gain the advantages of school-sponsored athletics to contribute to the safety of other players, the integrity of the game and their own well-being. The Supreme Court should leave these programs (45) .

A.addictions

B.conditions

C.addition

D.indulgence