- 博客(27)
- 资源 (2)
- 收藏
- 关注
原创 Bitmap操作
#include #include #include using namespace std;const int BYTESIZE = 8;void SetBit(char* p, int position){ for (int i = 0; i < position / BYTESIZE; i++) { p++; } *p = *
2014-04-26 22:13:28 925
原创 线索二叉树
#include #include #include using namespace std;struct BinThrNode{ int data;//结点的数据 BinThrNode* lChild;//左孩子 BinThrNode* rChild;//右孩子 bool lTag; //有左孩子是1 bool rTag; //有右孩子是1
2014-04-26 16:58:11 854
原创 并查集
#include using namespace std;void Init(){ for (int i = 0; i <= N; i++) { set[i] = i; }}int Find(int x){ return set[x] = (set[x] == x ? x : Find(set[x]));}int main()
2014-04-24 23:07:16 803
原创 非递归遍历便利二叉树
#include using namespace std;struct TreeNode{ TreeNode* lChild; TreeNode* rChild; int m_iData; TreeNode() { lChild = NULL; rChild = NULL; m_iData = 0;
2014-04-24 22:49:27 858
原创 哈希探查的三种方法
#include #include #include #include using namespace std;const int MAXSIZE = 100;int hash[MAXSIZE];int MOD = MAXSIZE - 1; //小于MAXSIZE的一个质数vector hashTable[MAXSIZE];/* 线性探查int LinearProbi
2014-04-24 21:41:51 1420
原创 快速幂
#include #include using namespace std;long long QuickPow(int a, int n, int mod){ int ans = 1; while (n) { if (n & 1) { ans = (long long)ans * a % mod;
2014-04-24 21:02:33 668
原创 函数传参
#include #include #include #include using namespace std;int Max(int a, int b){ return a > b ? a : b;}int GetMax(int a[][6], int N, int M){ int iMax = 0; for (int i = 0; i < N;
2014-04-22 20:48:41 906
原创 双栈模拟队列
#include #include using namespace std;templateclass CQueue{public: T& push(T&); T& front(); void pop();private: stack m_stack1; stack m_stack2;};templateT& CQueue:: pu
2014-04-19 20:13:25 946
原创 根据前序,中序求后续
#include #include #include #include #include using namespace std;void postOrder(char *pre, char *in, int len) { if (len <= 0) { return ; } int i; for (i = 0; i < len; i++) { if (in
2014-04-19 18:30:35 1395 1
原创 根据前序,中序构建出BinaryTree
#include #include #include using namespace std;struct TreeNode{ int m_iValue; TreeNode* m_pLeft; TreeNode* m_pRight; TreeNode() { m_pLeft = NULL; m_pRight =
2014-04-19 18:27:28 941
原创 洋气的SPFA
#include #include #include #include using namespace std;const int MAXN = 100 + 11;const int INF = 0x3FFFFFFF;class Edge{public: Edge(); ~Edge(); int getBegin(); void setBeg
2014-04-16 22:50:42 786
原创 虚函数的实现机制
#include using namespace std;class CBase1 { private: int a; int b; void sayBye() { cout << "Bye, CBase1!" << endl; } public: CBase1() { cout << "Hello CBase1!" << endl;
2014-04-16 20:19:43 827
原创 C++一些宏定义
#include #define PI 3.1415926 //#define #define MIN(X, Y) (X) () #define Conn(X, Y) X##Y //简单的把x和y连接起来,但不处理。即Conn(a, 2)--->a2, 编译的时候,如果没有a2就会报错。//#define TOCHAR(X) #@X 不可以这样使用#define TOSTRING(X
2014-04-16 13:13:52 843
原创 CreateThread()和_biginthreadex()
HANDLE WINAPI CreateThread( _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ SIZE_T dwStackSize, _In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter,
2014-04-15 20:04:43 1115
原创 堆排序
#include #include #include #include using namespace std;void print(int *a, int n){ for (int i = 1; i <= n; i++) { printf("%d ", a[i]); } cout << endl;}void heapify(int *a, int x, int
2014-04-14 11:39:13 804
原创 合并排序
#include #include #include #include const int INF = 0x7fffffff;using namespace std;void merge(int *a, int l, int mid, int r) { int L[100]; int R[100]; int cnt = 0; for (int i = l; i <=
2014-04-14 11:27:53 744
原创 快排(随机取数)
#include #include #include #include #include #include using namespace std;int partition(int *A, int L, int R, int p){ swap(A[p], A[R]); int i = L; int j = R; int pivot = A[R]; while (i
2014-04-14 11:15:10 830
原创 内存池的简单实现
#include using namespace std;templateclass SimpleMemPool{public: T* New() { if (!m_pFreeChunks) //如果空内存不存在,则重新申请一个大的block; { MemChunk* t = new MemChunk();
2014-04-14 10:55:56 858
原创 union的用法
#include #include using namespace std;union myUnion{ int m_iVar; char m_cVar[2];};int main(){ myUnion u; u.m_iVar = 0; cout << u.m_iVar << endl; u.m_cVar[0] = 11; //0
2014-04-13 22:58:36 728
原创 priority_queue的正确使用方法
其实priority_queue的正确用法:#include #include #include using namespace std;class Node{public: Node(){Node(0);} Node(int v): m_iVar(v){}; ~Node(){} bool operator < (Node& t); in
2014-04-13 22:28:07 1316
原创 swap的方法书写
#include using namespace std;int swap1(int& x, int& y){ x += y; y = x - y; x = x - y;}int swap2(int& x, int& y){ x ^= y; y ^= x; x ^= y;}int main(){ int x = 1,
2014-04-13 19:46:04 789
原创 自增、自减运算符的重载
#include using namespace std;class Increment{public: Increment(): m_iVar(0){}; ~Increment(); Increment& operator ++(); const Increment operator ++(int); int getVar();private
2014-04-13 19:31:42 1006
原创 自增、自减运算符的运算
#include using namespace std;int main(){ int a = 1; a = a+++a; // a = 3 int b = 1; b = b+++(++b);// b = 4; int c = 1; ++c = c+++c++;// c = 5; 第一部执行的是等号左边的++c return 0;
2014-04-13 19:09:49 1344
原创 operator new 和operator delete的重载应用
#include using namespace std;/* 重载后的operator new实现的功能是,看一看刚刚回收的垃圾堆上还有没有位置, 有位置的话,就直接拿一块下来,用来初始化。*/class FreeListBase{public: FreeListBase(): next(NULL){}; virtual ~FreeListBas
2014-04-13 18:31:29 851 1
原创 Singleton
#include using namespace std;/* 考虑多线程的Singleto实现方式,用局部静态变量也可以实现单例模型。单例模型就是解决创建对象时,只用维护一个对象的情况。*/ class Singleton{public: static Singleton* getInstance(); //静态函数 private: Singleton(); vir
2014-04-12 13:46:50 653
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人