提高篇第26-27课第三题
来源:互联网 发布:匿名网络举报网站 编辑:程序博客网 时间:2024/05/22 15:52
#include<stdio.h>#include<stdlib.h>//第三体,整型,字符型冒泡排序,选择排序void bubble_sort(int array[],int len);void output_array(int array[], int len);void char_bubble_sort(char c[], int len);//字符数组排序void char_output(char c[], int len);//字符数组输出void select_sort(int array[], int len);//选择排序int main(){int a[20] = { 86, 76, 62, 58, 77, 85, 92, 80, 96, 88, 77, 67, 80, 68, 88, 87, 64, 59, 61, 76 };int b[15] = { 27, 61, 49, 88, 4, 20, 28, 31, 42, 62, 64, 14, 88, 27, 73 };char c[20] = { 's', 'o', 'r', 't', 'b', 'u', 'b', 'b', 'l', 'e', 's', 'e', 'l', 'e', 'c', 't', 'o', 'k', 'o', 'k' };char d[15] = { 'a', 'b', 'a', 's', 'o', 'r', 't', 'b', 'u', 'b', 'b', 'l', 'e', 's', 'e' }; //自己补足bubble_sort(a, 20); //用冒泡法按降序排序a中元素output_array(a, 20); //输出排序后的数组bubble_sort(b, 15); //用冒泡法按降序排序b中元素output_array(b, 15); //输出排序后的数组char_bubble_sort(c, 20);char_output(c,20);char_bubble_sort(d, 15);char_output(d, 15);select_sort(a, 20);output_array(a, 20);return 0;}void bubble_sort(int array[], int len){int i,j,temp;for (i = 0; i < len - 1; i++)for (j = 0; j<len-i-1; j++){if (array[j] < array[j+1]){temp = array[j];array[j] = array[j+1];array[j+1] = temp;}}}void output_array(int array[], int len){int i;for (i = 0; i < len; i++)printf("%d ", array[i]);printf("\n");}void char_bubble_sort(char c[], int len){int i;int *array;array = (int*)malloc(len*sizeof(int));//动态定义len大小的整型数组for (i = 0; i < len; i++)array[i] = c[i];bubble_sort(array, len);for (i = 0; i < len; i++)c[i] = array[i];free(array);}void char_output(char c[], int len){int i;for (i = 0; i < len; i++)printf("%c ", c[i]);printf("\n");}void select_sort(int array[],int len){int i,j,temp;for (i = 0; i < len; i++)for (j = i; j < len;j++)if (array[j] < array[i]){temp = array[j];array[j] = array[i];array[i] = temp;}}
0 0
- 提高篇第26-27课第三题
- 提高篇第2-5课第三题
- 提高篇第6-10课作业第三题
- 提高篇第16-19课第三题
- 提高篇第20-21课第三题
- 提高篇第28-31课第三题
- 提高篇第26-27课第二题
- 第32课第三题
- 第33课第三题
- 第35课第三题
- 第36课第三题
- 第37课第三题
- 第39课第三题
- 第43课第三题
- 提高篇第2-5课第一题
- 提高篇第2-5课第二题
- 提高篇第2-5课第四题
- 提高篇第2-5课第六题
- 动物这样叫
- iMX6 Error Snapshot
- MySql获得当前日期时间
- Python列表切片详解([][:][::])
- 我为微商疗伤
- 提高篇第26-27课第三题
- C++ STL中哈希表 hash_map介绍
- ThreadLocal-分析-总结
- 点击缩小的自定义布局
- 通过Hook ZwCreateProcess获取进程全路径(缓存问题解决方案)
- 如何让网站所在虚拟主机支持apk格式文件下载
- 使用JAVA如何对图片进行格式检查以及安全检查处理
- SharedPreferences
- 考生经验谈:如何做好SAT阅读的时间掌控