等级考试上机题目(上课用)(19)
时间:2026-01-17
时间:2026-01-17
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);
}
2.程序修改题
#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;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");
19
下一篇:LED电子屏招标公告