- 博客(27)
- 资源 (3)
- 收藏
- 关注
原创 简单的正则表达式引擎
1、基础理论非确定有限自动机(NFA),是计算理论中抽象出来的状态机计算模型。它拥有有限个状态,当前状态根据不同的输入可以迁移到其他的状态,它的下一个状态不是唯一确定的。正则表达式本身是有限长度的字符串,在这里可以看做NFA上输入状态组成的序列。于是,NFA可以用来作为一种识别装置识别正则表达式。Thompson构造法:将正则表达式转换为NFA。这里的NFA包括ε状态及其转换,即不需要
2014-11-18 13:27:24 2525
原创 leveldb源码分析:Cache
cache.h只提供了接口,内部实现全部在cache.cc中。cache.cc中:LRUHandle是双向链表的节点结构HandleTable是一个hash表,其冲突采用链表的方法解决。它的作用主要是管理LRUCache的节点。LRUCache是一个采用LRU算法实现的Cache。ShardedLRUCache是一个Cache的具体使用,其继承自Cache类,内部有LRUCac
2016-05-02 17:46:36 616
原创 最简单的trie树
#include #include using namespace std;class TrieTree{ struct TrieNode{ bool isStr; TrieNode* child[26]; TrieNode():isStr(false){ for (int i = 0; i < 26; i++) child[i] = NULL; }
2015-05-04 22:50:42 531
原创 b树的c++实现
#include #include #include using namespace std;class BTree{ static const int M = 2; struct BTNode{ int keyNum; int key[2 * M - 1]; //关键字数组 struct BTNode* child[2 * M];//孩子结点数组 bool i
2015-05-03 23:09:50 1138 2
原创 b树的实现
#include #include #include #include #include #define M 2using namespace std;struct BTNode{ int keyNum; int key[2*M-1]; //关键字数组 struct BTNode* child[2*M];//孩子结点数组 bool isLeaf;};void D
2015-05-03 21:31:20 645
原创 排序大汇总
1.归并排序void merge(int *result, int begin, int mid, int end, int *temp){ int k = begin; int i = begin; int j = mid + 1; while (i <= mid&&j <= end){ temp[k++] = result[i] < result[j] ? result[i+
2015-04-27 19:44:50 608
原创 简单内存池实现
#include #include #include #include using namespace std;class MemPool{ struct FreeNode{ struct FreeNode* next; };private: static const int allocNum = 8; static const int step = 4; stati
2015-04-02 23:55:42 702
原创 1维KD-Tree查找指定范围内的元素
OneKdTree.h#include #include #include using namespace std;class AvlTree;class AvlNode{ friend class AvlTree; int data; int height; AvlNode *left; AvlNode *right; AvlNode(int _data) :da
2015-03-29 22:53:20 951
原创 二叉平衡树的详细实现:插入与删除
AvlTree.h#include #include #include using namespace std;templateclass AvlTree;templateclass AvlNode{ friend class AvlTree ; T data; int height; AvlNode *left; AvlNode *right; Avl
2015-03-29 19:08:58 794
原创 CSS规则树和HTML的DOM树合成渲染树时渲染结点与选择器链的匹配
在浏览器内核(排版引擎)CSS规则树和HTML的DOM树合成渲染树的时候,会涉及到渲染树的位置属性的问题,因为其位置属性将通过CSS选择器链的优先级来决定,而渲染树的某个结点可能会同时满足多个选择器链,这时候就要通过选择器的优先级来完成属性的赋值。在这个地方,我仅仅处理了几个简单的选择器情况:{(.class) (#id) (element) (#id,.clas
2014-12-12 21:41:52 1957 2
原创 kruskal算法
#include #include #include using namespace std;struct edge { int begin; int end; int cost;};bool cmp(edge a, edge b){ if (a.cost < b.cost) return true; return false;}int findSet(in
2014-12-07 22:58:45 628
原创 prim算法
#include using namespace std;int getMin(int *a, int n) { if (n <= 0) return 0; int min; for (int i = 0; i < n; i++) { if (a[i]) { min = i; break; } } for (int i = 0; i < n; i++) {
2014-12-07 19:38:20 588
原创 简单的vector实现
学习c++中,看完书后,最近苦于不知道下一步该怎么办了,就翻翻STL源码剖析中的各种容器,想重新实现一遍。很多问题之前看的时候还不知道是怎么回事,当自己写的时候才发现许多应该注意与理解的。这个vector类写得特别简单,只实现了其中的一部分功能,因为没有使用iterator,发现一些函数不太好写,而且封装性极差,同时,只能存放内置类型。在这些问题中,希望自己以后会好好重写一下。这个程序有点小情
2014-11-01 16:40:32 1388
原创 二叉树的先序、中序、后序的递归与非递归实现
#include #include #include using namespace std;struct BinTree { int data; struct BinTree *left; struct BinTree *right;};struct BinPost { BinTree *pTree; bool isFirst;};
2014-10-30 20:20:23 618
原创 跳表的实现
最近看了一下跳表,看了文章http://www.cnblogs.com/xuqiang/archive/2011/05/22/2053516.html的实现,本想参照这个流程用c++类实现一下,结果却出现一些问题,在vc++6.0中正常运行,在codeblocks中时好时坏,调试还会出现gdb停止工作。虽然觉得应该是内存问题,可是找半天找不到,泪奔啊~~~~如果有大神找到错误,请一定告
2014-10-29 21:48:44 813 1
原创 插入排序
复习一下原来学习的排序算法。#include using namespace std;void print(int *a,int n) { for(int i=0;i<n; ++i) { cout<<a[i]<<' '; } cout<<endl;}void InsertSort(int *a,int n) { int i,
2014-10-18 14:23:52 775
原创 STL源码剖析:空间配置器
看完自己重写了一下,不知道的又看了一遍。Mempool.h#ifndef MEMPOOL_H_#define MEMPOOL_H_#include #include #include namespace flysnow {enum {STEP_ = 8};enum {MAX_BYTES_ = 128};enum {FREELIST_NUM_ = MAX
2014-10-16 21:12:35 910
原创 The C++ Programming Language 第15章课后习题第三题
1.Board.h2.Board.cpp3.BoardTextView.h4.BoardTextV
2014-10-04 23:37:10 883
原创 C++程序设计语言课后习题10章15题
#include class A{public : A(){ std::cout } ~A(){ std::cout }};A a;int main(){ std::cout}
2014-10-01 09:52:44 761
原创 C++程序设计语言课后习题10章12题
#include #include using namespace std;class Char_queue{private: char *_queue; unsigned head,tail; unsigned const capacity; static unsigned const default_capacity = 20;public:
2014-09-30 15:41:10 981
原创 不通过类的成员函数直接访问类的私有变量
1.指针操作#include using namespace std;class object{private: int a; int b;public: object(int _a,int _b):a(_a),b(_b){} int get_a(){return a;} int get_b(){return b;}};int main()
2014-09-29 22:39:17 829
原创 STL list::sort算法
// list_sort.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;int main(){ list s; for(int k=15;k>=0;k--){ s.push_back(k
2014-09-10 13:25:10 552
原创 文本查询示例
最近看c++ primer,把15章最后的例子补充完整,贴出来。文本里的标点符号书中没有考虑,我改了改。#pragma warning(disable : 4786)#include #include #include #include #include #include #include #include using namespace std;class TextQuer
2014-08-14 23:10:07 499
原创 kd-tree c语言代码
/*This file is part of ``kdtree'', a library for working with kd-trees.Copyright (C) 2007-2009 John Tsiombikas Redistribution and use in source and binary forms, with or withoutmodification, are
2014-07-26 11:34:47 2718 6
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人