随笔分类 - C++
摘要:字典树,又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:利用字符串的公共前缀来节约存储空间,最大限度地减少无谓的字符串比较,查询效率比哈希表高。 字典树与字典很相似,当你要查一个单词是不是在字典树中,首先看单词的第一个字母是不是在字典的第一层,如果不在,说明字典树里没有该单词,如果在就在该字母的孩子节点里找是不是有单词的第二个字母,没有说明没有该单词,有的话用同样的方法继续查找.字典树不仅可以用来储存字母,也可以储存数字等其它数据。 TrieNode结构定...
阅读全文
摘要:老规矩,先来头文件StoreUtil.h#include <iostream>#ifndef SORTUTIL_H#define SORTUTIL_Hclass SortUtil{ public: template <class T> void MergeSort(T randomArray[], int left, int right); //归并推排序,left和right为下标 template <class T> void Merge(T A[], int left, int mid, int right); ...
阅读全文
摘要:头文件Maze.h#include<iostream>#include <ctime>#ifndef MAZE_H#define MAZE_Hconst char resultSymbol = '#';const char wallSymbolH = '-';const char wallSymbolV = '|';const char wallCorner = '+';const char roomSymbol = ' ';class Maze{public: char **maze; /
阅读全文
摘要:用于作业记录和复习#include <iostream>#include <string>#include <sstream>#include <fstream>using namespace std;//Link的节点结构class SNode{public: int data; SNode *next, *ahead; static SNode *freeNodeLink;//freeList技术,重用弃用空间,提高效率 SNode() { next = NULL; ahead = NULL; } ~SNode(){} /** *new操作符
阅读全文
摘要:推荐使用C++标准库作法:#include <iostream>#include <string>#include <sstream>using namespace std;int main(){ int a = 2; string b = "abc"; stringstream ss; ss << a << b; cout << ss.str() << endl; return 0;}
阅读全文
摘要:原文出处:goyello译文出处:外刊IT评论编程初学者总是把大量的时间用在学习编程语言,语法,技巧和编程工具的使用上。他们认为,如果掌握了这些技术技巧,他们就能成为不错的程序员。然而,计算机编程的目的并不是关于精通这些技术、工具的,它是关于针对特定领域里的特定问题创造出相应的解决方案,程序员通过相互合作来实现这些。所以,很重要的一点,你需要能精确的用代码表达出你的思想,让其他人通过代码能明白你的意图。让我们先看看编程大师Robert C. Martin的杰作《Clean Code |代码整洁之道》里的一句话:“注释的目的是为了弥补代码自身在表达上的不足。”这句话可以简单的理解为如果你的代码需
阅读全文
摘要:#include <iostream> #include <ctime>using namespace std;/********************************************************** Description:参数传递:C++ 二叉树的实现以及指针使用注意事项* Author:ADao12* DateTime:2013-05-30 02:27* Compile Environment:win8+vs2012***********************************************************/
阅读全文
摘要:By SmartPtr(http://www.cppblog.com/SmartPtr/) 说起C++的模板及模板特化, 相信很多人都很熟悉 ,但是说到模板特化的几种类型,相信了解的人就不是很多。我这里归纳了针对一个模板参数的类模板特化的几种类型, 一是特化为绝对类型; 二是特化为引用,指针类型;三是特化为另外一个类模板。这里用一个简单的例子来说明这三种情况:// general versiontemplate<class T>class Compare{public: static bool IsEqual(const T& lh, const T& rh) {
阅读全文
摘要:#include <iostream> #include <ctime>using namespace std;template<typename T>void selectSort(T a, int length){ for (int i = 0; i <= length-2; i++) { int minIndex = i; int minVal = a[i]; for (int j = i+1; j <=length-1; j++) { if (a[j] < minVal) { minIndex = j; minVal = a[j];
阅读全文
摘要:此算法乃复习数据结构用,不喜勿喷。。#include <iostream> #include <ctime>using namespace std;template<typename T>void bubbleSort(T a[], int order, int length){ switch (order) { case 0: for (int i = 0; i < length; i++) { for (int j = 1; j < length; j++) { if (a[j-1] > a[j]) { swap(a[j-1], a[j
阅读全文
摘要:此算法为复习数据结构笔记#include <iostream> #include <ctime>using namespace std;//// 两值交换. //template <typename T>void swap1(T &x, T &y){ T temp = x; x = y; y = temp;}//下标从0开始 template <typename T>int partition(T a[], int startIndex, int endIndex){//快速排序中的一趟 int i = startIndex; i
阅读全文

浙公网安备 33010602011771号