索引数组
来源:互联网 发布:linux 批量压缩文件夹 编辑:程序博客网 时间:2024/05/16 00:42
<span style="font-size:18px;">// 索引数组 int array[] = {3, 2, 6, 9, 8, 5, 7, 1, 4}; int count = sizeof(array) / sizeof(array[0]); int indexs[count]; for (int i = 0; i < count; i++) { indexs[i] = i; }// int flag = 1;// for (int i = 0 ; i < count - 1 && 1 == flag; i++) {// flag = 0;// for (int j = 0; j < count - i - 1; j++) {// if (array[indexs[j]] > array[indexs[j + 1]]) {// int temp = indexs[j];// indexs[j] = indexs[j + 1];// indexs[j + 1] = temp;// flag = 1;// }// }// } //索引数组 选择排序 int minIndex = 0; for (int i = 0; i < count - 1; i++) { minIndex = i; for (int j = minIndex + 1; j < count; j++) { if (array[indexs[minIndex]] > array[indexs[j]]) { minIndex = j; } } if (minIndex != i) { int temp =indexs[minIndex]; indexs[minIndex] = indexs[i]; indexs[i] = temp; } } for (int i = 0; i < count; i++) { printf("a[%2d] = %2d\n",indexs[i], array[indexs[i]]); }</span>索引数组:折半查找
<span style="font-size:18px;"> for (int i = 0 ; i < count; i++) { printf("[%d] : %d\n", indexs[i], array[indexs[i]]); } int start = 0 ,end = count - 1, mid = 0; printf("please input a number\n"); int target; scanf("%d", &target); //printf("%d\n", target); while (start <= end) { mid = (start + end) / 2; if (array[indexs[mid]] > target) { end = mid - 1; } else if (array[indexs[mid]] < target) { start = mid + 1; } else { break; } }</span>
0 0
- 索引数组
- 索引数组与删除数组
- 索引数组 和关联数组
- 关联数组转换索引数组
- 数组绘制中的索引
- opengl数组索引
- php----数组---索引
- 数组索引排序
- 数组自定义索引
- Flex索引数组
- 查询数组索引
- 二维数组 索引器
- ruby 数组索引
- 索引数组冒泡方法
- 非整数数组索引
- konckout 获取数组索引
- MATLAB数组索引
- PHP 索引数组合并
- 数组al[0,mid-1]和 al[mid,num-1],都分别有序。将其merge成有序数组al[0,num-1],要求空间复杂度O(1)
- 解决一则row cache lock引起的性能故障
- OpenCV 直线检测
- 如何在ACM客户端中临时挂起访问控制(AccessControl)的方案
- 交通银行信用卡积分有效期规则
- 索引数组
- QT编译Mysql数据库驱动
- poj 2773 Happy2006【容斥原理】
- log4j.properties 配置详解
- javaBean和Servlet的区别
- Moore状态机和Mealy状态机的区别
- 交通银行信用卡积分兑换商城礼品列表
- 第三届沈阳航空航天大学校赛(大连海事大学赛)---I: Spoors (预处理)
- hibernate4.14工具 单例