软考真题
第2题
【说明】
函数bubbleSort(int arr[], int n, int (*compare)(int,int))的功能是根据调用时传递的比较函数compare对数组arr的前n个元素进行排序。

【C代码】


#define swap(a, b) {
	a = a^b;
	b = a^b;
	a = a^b;
}
//交换a与b的值
​
int less(int x,int y) {
	return ((x
}
int larger(int x, int y) {
	return ((x>y) ? 1 : 0);
}
void bubbleSort(int arr[ ], int n, int (*compare)(int,int)) {
	int i,j;
	int swapped = 1;
	for ( i=0; swapped; i++) {
		swapped = 0;
		for (j=0; j
		if ( compare( arr[j+1], arr[j])) {
			swap( arr[j+1], arr[j]); 
			swapped =1;
		}
	}
}

【问题:2.1】阅读以下说明和C代码,回答问题,将解答写入答题纸的对应栏内。
设有如下数组定义:
int data1[ ] = {4, 2, 6, 3, 1};
int data2[ ] = {4, 2, 6, 3, 1};
int data3[ ] = {4, 2, 6, 3, 1};
请分别给出下面的函数调用执行后,数组data1、data2和data3各自的元素序列。
(1)bubbleSort(data1, 5, less);
(2) bubbleSort(data2, 5, larger);
(3) bubbleSort(data3, 3, larger);
排序
正确答案:
你的答案:
请先在App中激活(应用市场搜“软考真题”)
知识点:
试卷:
2019年 上半年 下午试卷 案例

笔记

商七

请先在App中激活(应用市场搜“软考真题”)

2023-10-24


布丁

请先在App中激活(应用市场搜“软考真题”)

2020-07-14


请先在App中激活(应用市场搜“软考真题”)

2019-10-29


请先在App中激活(应用市场搜“软考真题”)

2021-05-25


麦丽素

请先在App中激活(应用市场搜“软考真题”)

2022-03-04


请先在App中激活(应用市场搜“软考真题”)

2019-10-18


请先在App中激活(应用市场搜“软考真题”)

2019-11-07


请先在App中激活(应用市场搜“软考真题”)

2019-11-02


昔昔

请先在App中激活(应用市场搜“软考真题”)

2019-11-08


梦寐

请先在App中激活(应用市场搜“软考真题”)

2020-08-27


皮皮凯

请先在App中激活(应用市场搜“软考真题”)

2020-10-02


请先在App中激活(应用市场搜“软考真题”)

2019-11-03


凌晨

请先在App中激活(应用市场搜“软考真题”)

2020-11-01


请先在App中激活(应用市场搜“软考真题”)

2019-10-11


请先在App中激活(应用市场搜“软考真题”)

2019-10-20


请先在App中激活(应用市场搜“软考真题”)

2019-11-03


游客游客游客

请先在App中激活(应用市场搜“软考真题”)

2020-05-10


朱雨晨

请先在App中激活(应用市场搜“软考真题”)

2020-07-20


菠萝味团子

请先在App中激活(应用市场搜“软考真题”)

2020-10-12


QikY?

请先在App中激活(应用市场搜“软考真题”)

2021-03-19


tdd

请先在App中激活(应用市场搜“软考真题”)

2021-05-24


晓龙

请先在App中激活(应用市场搜“软考真题”)

2021-09-22


软考真题

请先在App中激活(应用市场搜“软考真题”)

2022-05-07


m2233m

请先在App中激活(应用市场搜“软考真题”)

2022-10-12


Tekken

请先在App中激活(应用市场搜“软考真题”)

2023-03-21


deng

请先在App中激活(应用市场搜“软考真题”)

2023-10-31


deng

请先在App中激活(应用市场搜“软考真题”)

2023-10-31


答题卡
加油
纠错
得分:0