算法修炼
文章平均质量分 67
FanTasyCC
这个作者很懒,什么都没留下…
展开
-
堆排序(源码 + 详细注释)
/* ary是存储记录的数组, start是需要调整为大顶堆的根记录下标, end是 它的最后一个叶子记录的下标。 注意,传入的start到end之间的记录,除去根记录,根记录的左右子二叉树都 是大顶堆, 要完全符合大顶堆的性质调用此函数才有效。 下面函数要做的就是调整以start为根记录,end为最后一个叶子记录的完全二叉树为大顶堆。 */void Heapify原创 2009-03-15 19:40:00 · 4192 阅读 · 2 评论 -
直接选择排序(C++描述)
void StraightSelectionSort(int array[], unsigned int n){ /* 注:关键字值类型为int,数组的索引是从0开始 1. 初始状态无序区为array【0, n - 1】,有序区为空。 2. 第1趟排序从array【0, n - 1】中找到下标为k的关键字最小值,把array【k】和 array【0】交换。现在无序区为a原创 2009-03-16 20:27:00 · 4104 阅读 · 0 评论 -
shell排序
typedef bool (*Func)(int a, int b);void ShellSort(vector& vec, Func fun){ int iSize = vec.size(); int iStep = iSize; int iCnt = 0; int iTmp = 0; do { iStep = iStep / 3 + 1; for原创 2009-07-14 09:12:00 · 570 阅读 · 0 评论 -
kmp算法求解next值
void GetNextVal(const char* str, vector& vec){ assert(str != NULL); if (str != NULL) { int iLen = strlen(str); vec.resize(iLen, -1); int i = 0; int j = -1; if (iLen > 0) {原创 2009-07-14 09:02:00 · 873 阅读 · 0 评论 -
环形buffer的两种设计方式
//CircleBuf.h#ifndef _CIRCLE_BUF_H#define _CIRCLE_BUF_H#pragma onceclass CCircleBuf{public: CCircleBuf(void);public: ~CCircleBuf(void); /* 环形缓冲区的两种实现方式 */ /* 通过增加一个标志来判断头尾值相等时,缓冲原创 2009-07-17 08:46:00 · 1902 阅读 · 0 评论 -
全排列算法递归实现(笔试题)
#include "stdafx.h"#include #include static int g_siANum[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};static int g_siCnt = 0;extern void TotalPermutation(int iarray[], int size, int index);extern vo原创 2009-07-14 15:10:00 · 957 阅读 · 0 评论 -
多线程扫描文件夹中的文件(经典模型)
#pragma oncestruct CMyDirectoryNode : public CNoTrackObject{ CMyDirectoryNode* pNext; TCHAR szDir[MAX_PATH];};struct CMyDir : public CNoTrackObject{ CMyDir* pNext; TCHAR szDir[MAX_PA原创 2010-04-15 17:41:00 · 2698 阅读 · 0 评论 -
利用二级指针删除单向链表节点
// testPPointer.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct tagNode{ struct tagNode* m_next; int m_nVal;}Node, *PNode;// 通过二级指针方式原创 2013-10-28 23:17:58 · 1819 阅读 · 0 评论