question1-在插入排序中运用二元搜索代替线性查找
来源:互联网 发布:java中什么是方法重载 编辑:程序博客网 时间:2024/06/16 20:04
int insertionSort(int *x, int n){ int i = 0, j = 0, k = 0, target = 0; for(i = 0; i < n-1; i++){ target = x[i+1]; j = binaryInsert(x, 0, i, target); //找出需要插入的 位置j for(k = i; k > j; k--) //更改数据 ? T(n) = ? x[k+1] = x[k]; x[j+1] = target; } for(i = 0; i < n; i++) cout<<"x["<<i<<"] = "<<x[i]<<endl; return 0;}int binaryInsert(int *x, int p, int q, int target){ if(p > q) return q; else{ int mid = (p+q)/2; if(x[mid] < target) return binaryInsert(x, mid+1, q, target); else if(x[mid] > target) return binaryInsert(x, p, mid-1, target); else return mid; }}int test(void){ int x[] = {3,2,1}; int n = (sizeof x)/4; insertionSort(x, n); return 0;}
0 0
- question1-在插入排序中运用二元搜索代替线性查找
- 快速排序中运用插入排序算法
- Question1
- Question1
- 二元查找树-- 在二元树中找到和为某一值的所有路径
- 插入元素到二元查找树
- 二叉搜索(排序)树的 查找、插入、删除
- 指针初步学习,运用指针进行冒泡排序,选择排序,插入排序和折半查找
- 线性表中实现查找、删除、插入元素
- 二元查找树转化为排序双链表
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- 在二叉查找树中插入节点
- BusyBox 官网 Frequently Asked Questions
- Internal Sorting: List Merge Sort: Sorting by Merging
- ubuntu系统下源的问题
- solr5.0 tomcat安装部署
- 容器+AOP 实现动态部署(二)
- question1-在插入排序中运用二元搜索代替线性查找
- Vijava 学习笔记(指定虚拟机添加虚拟磁盘修订功能版本)
- Tk on Python
- Mac 下解压Android NDK 的 .bin文件
- Welcome to Linux From Scratch!
- 数据结构与算法分析-栈
- 20 款超棒免费的 Bootstrap 管理和前端模板
- 移植busybox-1.14.0
- <fmt:parseNumber/>解析数字