微信搜索关注"91考试网"公众号,领30元,获取公务员、事业编、教师等考试资料40G!
第7套题
一、程序填空题
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h)
{ SLIST *p, *q;
p=h->next;
if (p!=NULL)
{ q=p->next;
while(q!=NULL)
{ if (p->data==q->data)
{ p->next=q->next;
/**********found**********/
free(___1___);
/**********found**********/
q=p->___2___;
}
else
{ p=q;
/**********found**********/
q=q->___3___;
}
}
}
}
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i<N; 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("->End\n");
}
}
main( )
{ SLIST *head; int a[N]={1,2,2,3,4,4,4,5};
head=creatlist(a);
printf("\nThe list before deleting :\n"); outlist(head);
fun(head);
printf("\nThe list after deleting :\n"); outlist(head);
}
二、程序改错题
#include <stdio.h>
#define N 20
void fun(int a[], int n)
{ int i, j, t, p;
for (j = 0 ;j < n-1 ;j++) {
/************found************/
p = j
for (i = j+1;i < n; i++)
if(a[i] < a[p])
/************found************/
p = j;
t = a[p] ; a[p] = a[j] ; a[j] = t;
}
}
main()
{
int a[N]={9,6,8,3,-1},i, m = 5;
printf("排序前的数据:") ;
for(i = 0;i < m;i++) printf("%d ",a[i]); printf("\n");
fun(a,m);
printf("排序后的数据:") ;
for(i = 0;i < m;i++) printf("%d ",a[i]); printf("\n");
}
三、程序编写题
#include <stdio.h>
#define M 100
void fun ( int m, int *a , int *n )
{