(算法设计技巧与分析)InsertionSort
2015-03-10 00:34
561 查看
#include<iostream> #include<time.h> using namespace std; void InsertionSort(int a[],int n); int main() { int a[11]; srand((unsigned int(time(NULL))));//导入时间种子加每次运行结样试下伪随机数种子 for (int i=0;i<11;i++) a[i]=rand(); InsertionSort(a,11); for(int i=0;i<11;i++) cout<<a[i]<<" "; return 0; } void InsertionSort(int a[],int n) { n--; if(n>0) { InsertionSort(a,n); int temp=a ; while(n>0&&a[n-1]>temp) {a =a[n-1];n--;} a =temp; /* for(int i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;*/ } }
相关文章推荐
- (算法设计技巧与分析)InsertionSort
- (算法设计技巧与分析)RadixSort
- (算法设计技巧与分析)LinearSearch
- (算法设计技巧与分析)SelectSort
- (算法设计技巧与分析)matchain
- 算法设计技巧和分析学习笔记1 (归纳法、分治和动态规划)
- (算法设计技巧与分析)Kruskal
- (算法设计技巧与分析)BinarySearch
- (算法设计技巧与分析)BinarySearchrec
- (算法设计技巧与分析)floyd
- (算法设计技巧与分析)QuickSort
- 第十一周算法分析与设计: Sort Colors
- <算法设计技巧与分析>M.H>Alsuwaiye编著 读书心得
- (算法设计技巧与分析)SelectionSortFec
- (算法设计技巧与分析)Knapsack
- (算法设计技巧与分析)CloseStpair
- (算法设计技巧与分析)Permutationsi
- (算法设计技巧与分析)Majority
- (算法设计技巧与分析)prim
- (算法设计技巧与分析)Dijkstra