直接插入排序的实现(递归和非递归)

2014-11-24 00:40:28 · 作者: · 浏览: 4
// 递归和非递归实现直接插入排序.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include 
using namespace std;

//插入排序(非递归)
void InsertSort(int *pArr, int nLength)
{
	if (pArr == NULL || nLength <= 0)
	{
		return;
	}
	 
	int key = 0;
	int j=0;
	for (int i=1; i=0&&key
= nLength) { return; } int key = pArr[index];//记录当前待插入的元素 int i=0; for (i=index-1; i>=0&&key