Hackerrank && Insertion Sort - Part 1
来源:互联网 发布:js 数组 json 编辑:程序博客网 时间:2024/04/30 05:28
#include <iostream>using namespace std ;int main(){int n ;cin >> n ;int a[n] ;for ( int i = 0 ; i < n ; ++i) cin>>a[i] ; bool flag = false ;int temp = a[n-1];for ( int i = n-2 ; i >= 0 ;--i) { if (a[i]>temp) { a[i+1] = a[i] ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; if (i==0) { a[i] = temp ; //a[i] = temp ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; } } else { a[i+1] = temp ; temp = a[i] ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; break ; } } return 0 ;}这是insert排序的 初步 排序,这里面 把最后一个当做了哨兵,然后 与前面的元素相比较 。。。
0 0
- Hackerrank && Insertion Sort - Part 1
- 【hackerrank】Insertion Sort Advanced Analysis
- 【hackerrank】Insertion Sort Advanced Analysis
- Insertion Sort - Part 2
- Sort Algorithm Part-2 Insertion Sort
- Insertion Sort
- Insertion Sort
- insertion sort
- insertion sort
- Insertion Sort
- insertion sort
- insertion sort
- insertion sort
- insertion sort
- Insertion Sort
- Insertion Sort
- Insertion-sort
- Insertion sort
- 基本java算法
- 【AC自动机+DP+大数】 POJ 1625 Censored!
- 刘徐阳总结的一些编程总结
- GLFW初步接触
- WebApp与Native App区别
- Hackerrank && Insertion Sort - Part 1
- 暂时知道的大型移动开发者开放平台(求补充)
- UI设计理念——用简洁的道理说明一切
- 谈下论坛和商城的开发项目
- php简单导出excel
- 【网络流】 HDU 3605 Escape 缩图
- 比较好的一份面试题
- 大学三年总结
- 树状数组