計算機二級

當前位置 /首頁/計算機/計算機二級/列表

計算機二級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);

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