返回信息流#include<iostream>
using namespace std;
void insertsort(int a[],int n)
{
int j;
for(int i=1;i<n;i++)
{
if(a[i]<a[i-1])
{
int temp=a[i];
for(j=i-1;a[j]>=temp;j--)
{
a[j+1]=a[j];
}
a[j+1]=temp;
}
}
}
int main()
{
int a[]={3,2,6,4,8,6,5,3,-2,-2,9,0};
for(int i=0;i<sizeof(a)/sizeof(int);i++)
cout<<a[i]<<" ";
cout<<endl;
insertsort(a,sizeof(a)/sizeof(int));
for(int i=0;i<sizeof(a)/sizeof(int);i++)
cout<<a[i]<<" ";
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #95067同步于 2017/4/9
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
直接插入排序
bingge
2017/4/9镜像同步11 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
我应该怎么学使用调试器?
【 在 Vampire (Vampire) 的大作中提到: 】
: 楼主你不要放弃这个学习使用调试器的机会啊……
通过『我邮2.0』发布
gdb:
https://www.gnu.org/software/gdb/documentation/
http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html
lldb:
https://lldb.llvm.org/tutorial.html
【 在 bingge 的大作中提到: 】
: 我应该怎么学使用调试器?
:
: 通过『我邮2.0』发布
[ema11]
【 在 Vampire 的大作中提到: 】
: gdb:
: https://www.gnu.org/software/gdb/documentation/
: http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html
: ...................
【 在 bingge 的大作中提到: 】
: #include<iostream>
: using namespace std;
: void insertsort(int a[],int n)
: ...................
```
void InsertSort(vector<int>& nums) {
int n = nums.size();
if (n <= 1) return;
for (int i = 1; i < n; i++) {
for (int j = i; j > 0 && nums[j] < nums[j - 1]; j--) {
swap(nums[j], nums[j - 1]);
}
}
return;
}
```
秀一下Haskell语言:
module InsertSort where
insertElem :: Ord a => a -> [a] -> [a]
insertElem y [] = [y]
insertElem y (z:zs)
| y <= z = y:z:zs
| otherwise = z:(insertElem y zs)
insertSort :: Ord a => [a] -> [a]
insertSort [] = []
insertSort (x:xs) = insertElem x $ insertSort xs
暖神666
暖神帮我看看那个堆排序的问题出在哪里了
https://bbs.byr.cn/#!article/CPP/95074
【 在 nuanyangyang 的大作中提到: 】
: 秀一下Haskell语言:
: [code=haskell]
: module InsertSort where
: ...................