随笔分类 -  算法与数据结构

shell 排序
摘要:// shellSort.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>using namespace std;/* 算法思想: 1,初始化增量大小,increment = 0; 2,以增量大小变化为循环 依次减小增量 直到增量为1 停止循环 3,在循环体内 设置增量变化公式,从start+增量的位置开始 依次比较大小 若前面的大于后面的, 则:①首先把当前位置保存下来,然后用前面相隔相同增量的较小的覆盖,直到完毕后,在把最前面的赋值为保存的值。*/void ShellSort(in... 阅读全文
posted @ 2012-09-12 17:47 TianMG 阅读(167) 评论(0) 推荐(0)
归并排序
摘要:直接给代码 原理就不啰嗦了;View Code 1 void OutPut(int *arr,int len) 2 { 3 for(int i=0; i < len; ++i) 4 { 5 cout<<arr[i]<<" "; 6 } 7 cout<<endl; 8 } 9 //序列a1为两个有序的子序列,a1[s...m] 和 a[m+1,e]有序10 // 把a1的两个有序子序列合并为一个有序数列a211 void Merge(int* a1,int* a2, int s, int m, int e)12 {13 int k,j 阅读全文
posted @ 2012-09-11 16:20 TianMG 阅读(173) 评论(0) 推荐(0)
堆排序算法的实习(C++)
摘要:View Code 1 //HeapSort.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 7 using namespace std; 8 9 //此函数为大顶堆调整函数10 void HeapAdjust(int* arr,int start, int end)11 {12 int temp;//用作交换的存储单元,此算法的空间复杂度为此。13 int j=0;//关键字较大的节点位置14 temp = arr[start];15 for(j = s... 阅读全文
posted @ 2012-09-11 14:08 TianMG 阅读(188) 评论(0) 推荐(0)