首页 > 编程语言 > 详细

排序---直接插入

时间:2015-06-18 13:34:48      阅读:375      评论:0      收藏:0      [点我收藏+]
#include<iostream>
using namespace std;
#define SIZE 21
typedef int Sqlist[SIZE];

void InsretSort(Sqlist &L,int n) 
{
   for(int i=2;i<n;++i)
   {
      L[0] = L[i];
	  for(int j=i;L[0] < L[j-1];--j)
	  {
	     L[j] = L[j-1];
	  }
	  L[j] = L[0];
   }
}
void main()
{
	Sqlist L= {0,49,38,65,97,76,13,27};
	InsretSort(L,8);//直接插入
	for(int i=1;i<8;++i)
	  cout<<L[i]<<" ";
	cout<<endl;
}

技术分享

排序---直接插入

原文:http://blog.csdn.net/zr1076311296/article/details/46546563

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!