二级C语言机试真题2007年04月
1、程序填空题
1. 请补充fun函数,该函数的功能是:将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 [注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。 [试题源程序] #include <stdio.h> #include <stdlib.h> #define N 5 typedef Struct node { int data;
struct node *next; }NODE;
void fun(NODE *h) {
NODE *p, *q, *r; p= ; if ( ) return; q=P->next; P->next=NULL; while (q) {
r=q->next; q->next=p;
p=q; q= ; }
h->next=p; }
NODE *creatlis (int a[]) {
NODE *h, *p, *q; int i;
h= (NODE *)malloc(sizeof(NODE)); h>next=NULL: for(i=0; i<N; i++) {
q=(NODE *)malloc(sizeof(NODE)); q->data=a[i]; q->next=NULL; if(h->next==NULL) h->next=p=q; else {
p->next=q; p=q; } } return h; }
void ou list(NODE *h) { NODE *p; p=h->next; if(p==NULL)
printf(\
相关推荐: