- 博客(9)
- 收藏
- 关注
转载 for_each调用类成员函数,mem_fun, mem_fun_ref用法
先看一个STL中for_each的用法[cpp] view plaincopy#include #include #include #include #include using namespace std; class Test { public: Test(int _
2015-11-29 22:13:58 764
原创 输入输出重定向,迭代器绑定cin
Linux环境中支持输入输出重定向,用符号来表示。0、1和2分别表示标准输入、标准输出和标准错误信息输出,可以用来指定需要重定向的标准输入或输出,比如 2>lee.dat 表示将错误信息输出到文件lee.dat中。同时,还可以在这三个标准输入输出之间实现重定向,比如将错误信息重定向到标准输出,可以用 2>&1来实现。Linux下还有一个特殊的文件/dev/null,它就像一个无底洞,所
2015-11-29 21:22:52 488
原创 insertSort,quickSort,mergeSort
http://blog.csdn.net/onlyou2030/article/details/48108573已经包含了插入排序。下面是STL排序实现,省去了边界判断,在大量数据的情况下,影响是可观的。当然时间复杂度:O(n^2)#include #include #include using namespace std;int * copy_backward(int
2015-11-27 19:41:45 509
原创 next_permutation,prev_permutation
1.next_permutation会取得[first,last)所标示的序列的下一个排列组合。如果没有下一个排列组合,便返回false;否则返回true。其实现算法如下:首先,从最尾端开始往前寻找两个相邻元素,令第一元素为*i,第二元素为*ii,且满足*i找到这样一组相邻元素后,再从尾端开始往前检验,找出第一个大于*i的元素,令其为*j,将i,j元素对调,再将ii之后的所有元素颠倒排
2015-11-27 18:24:27 291
原创 find_end, search
STL算法里面有两个查找子序列的函数,分别是find_end和search。由于两者比较像,所以我将两者实现列出比较,并附上使用的例子。1.find_end功能是在序列一[first1,last1)所涵盖的区间中,查找序列二[first2,last2)。如果序列一之内不存在,返回迭代器last1,否则返回最后一次出现对应的迭代器。实现如下:template ForwardItera
2015-11-27 17:49:21 449
原创 exception,smart_ptr
// Workshop 9 - Smart Pointers// w9.cpp#include #include #include "Element.h"#include "List.h"const int FWC = 5;const int FWD = 12;const int FWP = 8;w9::List merge(const w9::List& desc,cons
2015-11-26 14:23:00 264
原创 RBTree
#ifndef RBTREE_H_#define RBTREE_H_#include #include using namespace std;#define BLACK 0#define RED 1struct Node{ int key; //节点键值 string ID; int color; //节点颜
2015-11-24 10:40:25 356
原创 heap
//最大堆#ifndef HEAP_H_#define HEAP_H_#include using namespace std;class Heap{private: vector heapData; int heapSize; //堆中元素的个数public: Heap(int *arr,int n);
2015-11-23 15:33:15 249
原创 double list
#ifndef LIST_H_#define LIST_H_struct Node{ int data; Node *next; Node *pre; Node(int d){ data = d; }};class List{public: List(); List(int *arr, int size); //根据数组构造链表 ~List(); Node
2015-11-21 12:04:51 410
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人