自考2243-计算机软件基础(-)2007年版课后习题答案 下载本文

内容发布更新时间 : 2024/5/31 23:33:14星期一 下面是文章的全部内容请认真阅读。

4. n-1

5. 线性表的长度 三、改错 1. 不唯一

2. 有关,参看简答第一题 3. 链式存储也可以 4. 该说法是正确的。 四、选择

C 第二题不会,呵呵. BAD 五、算法设计题 1.

#include

#define MAX 100

struct Link {

int data[MAX] ; int n ; };

int serarch(Link *list , int searchValue) { int i ;

list->data[list->n] = searchValue ;

for(i = 1 ; list->data[i] != list->data[list->n] ; ++i) ; return i ; }

int main() {

struct Link l ; int i , n1 , n2 ;

scanf(\ for(i = 0 ; i < l.n ; ++i) scanf(\ scanf(\ n2 = serarch(&l , n1) ; if(n2 != l.n + 1) printf(\ return 0 ; } 2.

struct Node {

int data ;

struct Node *left ; struct Node *right ; };

//先序遍历

void fun(struct Node *t) { if(t != NULL) { if(t->data % 2 == 0) printf(\ fun(t->left) ; fun(t->right) ; } }

第十三章

一、 简答题 1. 197页

2. 插入排序、冒泡排序 3. 插入排序 : 35 78 12 35 78 12 26 35 78 12 26 35 78 90 12 26 35 41 78 90 12 26 35 41 66 78 90

12 26 35 41 58 66 78 90

选择排序

12 78 35 26 90 41 66 58 12 26 35 78 90 41 66 58 12 26 35 78 90 41 66 58 12 26 35 41 90 78 66 58 12 26 35 41 58 78 66 90 12 26 35 41 58 66 78 90 12 26 35 41 58 66 78 90 共需n-1趟

冒泡:

35 12 26 78 41 66 58 90 12 26 35 41 66 58 78 90 12 26 35 41 58 66 78 90

12 26 35 41 58 66 78 90 //此趟没有进行交换,作为终止条件 二、填空题

1. 数据处理 2. 4 3. 2 4. 7 5. 1 三、改错

1. 不稳定排序 2. 正确

3. 正确位置上 4. 该说法正确 四、单选 CAACD

五、程序设计题 1.

#include #include

struct Node { int data ;

struct Node *next ; };

struct Node * fun(struct Node *list1 , struct Node *list2) { struct Node *h1 , *h2 , *p2 ;

for(h1 = list1->next ; h1 != NULL ; ) { for(p2 = list2 , h2 = list2->next ; h2 != NULL ; h2 = h2->next , p2 = p2->next) { if(h1->data < h2->data) { break ; } } //从list1中删除节点 list1->next = h1->next ; //在list2插入节点 h1->next = h2 ; p2->next = h1 ; h1 = list1->next ; //h1重新指向list1的第一个节点 }

return list2 ; }

int main() {

struct Node *head1 = (struct Node *) malloc(sizeof(struct Node)) ; struct Node *head2 = (struct Node *) malloc(sizeof(struct Node)) ; struct Node *p ; int n1 , n2 , i , t ;

scanf(\ head1->next = NULL ; for(i = 0 ; i < n1 ; ++i) { p = (struct Node *) malloc(sizeof(struct Node)) ; scanf(\ p->next = head1->next ; head1->next = p ; }

scanf(\ head2->next = NULL ; for(i = 0 ; i < n2 ; ++i) { p = (struct Node *) malloc(sizeof(struct Node)) ; scanf(\ p->next = head2->next ; head2->next = p ; }

head1 = fun(head1 , head2) ;

for(p = head2->next ; p != NULL ; p = p->next) printf(\ return 0 ; } 2.

#include

int main() {

int i , a[10] ;

for(i = 0 ; i < 10 ; ++i) a[i] = i ; return 0 ; }