摘要:#include#include#include#includeusing namespace std;struct Node;//二叉树节点 class Node{ public: Node(int node):parent(NULL),left(NULL),right(NUL...
阅读全文
摘要:templatevoid swap(T* a, T* b){ T temp = *a; *a = *b; *b = temp;}//数组的全排列void perm(int list[], int k, int m){ if (k==m) { copy(list,list+m...
阅读全文
摘要://堆排序//①维护堆 void max_heapify(int *ptr,int index,int len){ index = index + 1; int left = index ptr[index - 1]) largest = left; if(righ...
阅读全文
摘要:#include using namespace std;void swap(int* p,int* q){ int temp = *p; *p = *q; *q = temp;}//快速排序int partition(int *ptr,int first, int last){ ...
阅读全文
摘要:#include using namespace std;void merge(int* ptr,int first, int mid, int last){ int len = last - first + 1; int *temp = new int[len]; ...
阅读全文
摘要:templateT my_search(T first1, T last1, T first2, T last2){ int d1 = distance(first1, last1); int d2 = distance(first2, last2); if(d1 < d2) ...
阅读全文
摘要:转:http://www.cnblogs.com/kekec/archive/2011/07/22/2114107.html
阅读全文
摘要:1、用itoa 和atoi 在头文件#includeitoa用法:char * itoa ( int value, char * str, int base );valueValue to be converted to a string.strArray in memory where to s...
阅读全文
摘要:#includeusing namespace std;class binaryNode{ public: binaryNode(int &a):key(a),p(NULL),Left(NULL),Right(NULL){ } binaryNode* p; ...
阅读全文
摘要:C风格转换是“万能的转换”,但需要程序员把握转换的安全性,编译器无能为力;static_cast最接近于C风格转换,但在无关类指针转换时,编译器会报错,提升了安全性;dynamic_cast要求转换类型必须是指针或引用,且在下行转换时要求基类是多态的,如果发现下行转换不安全,dynamic_ca...
阅读全文
摘要:希尔排序: 基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组。所有距离为d1的倍数的记录放在同一个组中。先在各组内进行直接插入排序;然后,取第二个增量d2=1; dk=dk/2) { cout =0&&key<a[j];j-=dk) ...
阅读全文
摘要:#include#include#include#include"PRINT_ELEMENTS.h"using namespace std;class Nth{ private: int nth; int count; public: Nth(int n):nth(n),count(0){ } bool operator()(int){ return ++count==nth; }};int main(int argc, char **argv){ list coll...
阅读全文
摘要:语法: const char *c_str();c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同. 这是为了与c语言兼容,在c语言中没有string类型,故必须通过string类对象的成员函数c_str()把string 对象转换成c中的字符串样式。注意:一定要使用strcpy()函数 等来操作方法c_str()返回的指针 比如:最好不要这样: char* c; string s="1234"; c = s.c_str(); //c最后指向的内容是垃圾,因为s对象被析构,其内容被处理应该这样用: char c[20]; string s=&qu
阅读全文
摘要:字串格式化命令,主要功能是把格式化的数据写入某个字符串中。把格式化的数据写入某个字符串缓冲区。
阅读全文
摘要:非const引用,只能用object为其赋值; 《c++primer》P52 而const引用则可以用临时变量为其赋值; 如: const int &r = 32;//可以 int &rr = 32 // error而且:非const引用只能绑定到与该引用同类型的对象;const引用则可以绑定到不同但相关的类型的对象或绑定到右值;//左值:可以出现在赋值语句的坐标或右边;右值:只能出现在赋值的右边。当进行string对象和字符串字面值混合连接操作是,+操作符的左右操作数必须至少有一个是string类型1、字符指针数组创建:char **parr = new char*[n];。
阅读全文
摘要:引言C++ STL可以分为标准容器,算法和函数对象,迭代器和分配器,利用C++标准程序库,可以大量减少我们的代码,提高代码的稳定性和健壮性。标准容器C++标准容器分为序列容器和关联容器,对于序列容器,C++提供的基本序列有vector 支持随机访问,不适合做插入和删除操作频繁的场景list 双向链表,适合做元素的插入和删除,不是随机访问deque 也是一个双端序列,但是经过优化,其双端操作效率类似list,随即访问效率接近vector。从它们出发,通过定义适当的借口,生成了stack 默认用deque实现queue 默认是deque实现priority_queue 默认是vector保存元素,
阅读全文
摘要:#ifndef HANDLE_H#define HANDLE_H#include <cstddef>//泛型句柄类template<typename T>class Handle {public: Handle(T *p = 0):ptr(p), use(new std::size_t(1)) { } Handle(const Handle &h):ptr(h.ptr), use(h.ptr) { ++*use; } T& operator* (); T* operator->(); const T& operator* () const;
阅读全文
摘要:---恢复内容开始---1。定义函数指针:typedef bool (*Comp) (const Sale_item&, cosnt Sale_item&);---恢复内容结束---
阅读全文