糯米文學吧

位置:首頁 > 計算機 > 計算機二級

計算機二級C語言上機題庫及答案2017

引導語:我們將要迎來2017年9月份的計算機考試,大家準備好了嗎,以下是本站小編分享給大家的計算機二級C語言上機題庫及答案2017,歡迎測試!

計算機二級C語言上機題庫及答案2017

一、填空題

給定程序中已建立一個帶有頭結點的單向鏈表,在main函數中將多次調用fun 函數,每調用一次fun函數,輸出鏈表尾部結點中的數據,並釋放該結點,使鏈表縮短。

請在程序的.下劃線處填入正確的內容並把下劃線刪除,使程序得出正確的結果。

注意:源程序存放在考生文件夾下BLANK1.C中。

不得增行或刪行,也不得更改程序的結構!

給定源程序:

#include

#include

#define N 8

typedef struct list

{int data;

struct list *next;

} SLIST;

void fun(SLIST *p)

{SLIST *t, *s;

t=p->next; s=p;

while(t->next != NULL)

{s=t;

/**********found**********/

t=t->___1___;

}

/**********found**********/

printf(" %d ",___2___);

s->next=NULL;

/**********found**********/

free(___3___);

}

SLIST *creatlist(int *a)

{SLIST *h,*p,*q; int i;

h=p=(SLIST *)malloc(sizeof(SLIST));

for(i=0; 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("->Endn");

}

}

main()

{SLIST *head;

int a[N]={11,12,15,18,19,22,25,29};

head=creatlist(a);

printf("nOutput from head:n"); outlist(head);

printf("nOutput from tail: n");

while (head->next != NULL){

fun(head);

printf("nn");

printf("nOutput from head again :n"); outlist(head);

}

}

解題答案:

/**********第一空**********/

t=t->next;

/**********第二空**********/

printf(" %d ",t->data);

/**********第三空**********/

free(t);

******************************************