随笔分类 -  C++

二叉树遍历 (前序 层次 == 深度 广度) 层次遍历
摘要:#include#include#include#includeusing namespace std;struct Node;//二叉树节点 class Node{ public: Node(int node):parent(NULL),left(NULL),right(NUL... 阅读全文

posted @ 2014-09-05 09:48 yi_meng 阅读(352) 评论(0) 推荐(0) 编辑

数组全排列 knuth 分解质因数
摘要: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... 阅读全文

posted @ 2014-09-04 19:41 yi_meng 阅读(548) 评论(0) 推荐(0) 编辑

堆排序
摘要://堆排序//①维护堆 void max_heapify(int *ptr,int index,int len){ index = index + 1; int left = index ptr[index - 1]) largest = left; if(righ... 阅读全文

posted @ 2014-08-26 10:40 yi_meng 阅读(134) 评论(0) 推荐(0) 编辑

双向快速排序
摘要:#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){ ... 阅读全文

posted @ 2014-08-25 20:32 yi_meng 阅读(753) 评论(0) 推荐(0) 编辑

二路归并排序
摘要:#include using namespace std;void merge(int* ptr,int first, int mid, int last){ int len = last - first + 1; int *temp = new int[len]; ... 阅读全文

posted @ 2014-08-25 19:04 yi_meng 阅读(212) 评论(0) 推荐(0) 编辑

字符串的排列
摘要:字符串排列 阅读全文

posted @ 2014-06-06 23:04 yi_meng 阅读(285) 评论(0) 推荐(0) 编辑

求字符串2是是否是字符串1的字串
摘要:templateT my_search(T first1, T last1, T first2, T last2){ int d1 = distance(first1, last1); int d2 = distance(first2, last2); if(d1 < d2) ... 阅读全文

posted @ 2014-05-04 11:00 yi_meng 阅读(469) 评论(0) 推荐(0) 编辑

memcpy 和memmove的区别
摘要:转:http://www.cnblogs.com/kekec/archive/2011/07/22/2114107.html 阅读全文

posted @ 2014-04-30 15:49 yi_meng 阅读(158) 评论(0) 推荐(0) 编辑

最近遇到的C++数字和字符串的转换问题
摘要: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... 阅读全文

posted @ 2014-04-28 11:02 yi_meng 阅读(438) 评论(0) 推荐(0) 编辑

二叉搜索树
摘要:#includeusing namespace std;class binaryNode{ public: binaryNode(int &a):key(a),p(NULL),Left(NULL),Right(NULL){ } binaryNode* p; ... 阅读全文

posted @ 2014-04-25 10:01 yi_meng 阅读(229) 评论(0) 推荐(0) 编辑

C++类型的转换
摘要:C风格转换是“万能的转换”,但需要程序员把握转换的安全性,编译器无能为力;static_cast最接近于C风格转换,但在无关类指针转换时,编译器会报错,提升了安全性;dynamic_cast要求转换类型必须是指针或引用,且在下行转换时要求基类是多态的,如果发现下行转换不安全,dynamic_ca... 阅读全文

posted @ 2014-04-23 21:00 yi_meng 阅读(213) 评论(0) 推荐(0) 编辑

希尔排序
摘要:希尔排序: 基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组。所有距离为d1的倍数的记录放在同一个组中。先在各组内进行直接插入排序;然后,取第二个增量d2=1; dk=dk/2) { cout =0&&key<a[j];j-=dk) ... 阅读全文

posted @ 2014-04-20 20:29 yi_meng 阅读(203) 评论(0) 推荐(0) 编辑

remove_if的问题
摘要:#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... 阅读全文

posted @ 2013-11-19 10:36 yi_meng 阅读(338) 评论(0) 推荐(0) 编辑

string 复制给char[] 即:c_str() 用法:
摘要:语法: 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 阅读全文

posted @ 2013-11-17 15:02 yi_meng 阅读(3582) 评论(0) 推荐(0) 编辑

sprintf
摘要:字串格式化命令,主要功能是把格式化的数据写入某个字符串中。把格式化的数据写入某个字符串缓冲区。 阅读全文

posted @ 2013-09-10 17:55 yi_meng 阅读(142) 评论(0) 推荐(0) 编辑

c++引用和const 用法 数组 指针
摘要:非const引用,只能用object为其赋值; 《c++primer》P52 而const引用则可以用临时变量为其赋值; 如: const int &r = 32;//可以 int &rr = 32 // error而且:非const引用只能绑定到与该引用同类型的对象;const引用则可以绑定到不同但相关的类型的对象或绑定到右值;//左值:可以出现在赋值语句的坐标或右边;右值:只能出现在赋值的右边。当进行string对象和字符串字面值混合连接操作是,+操作符的左右操作数必须至少有一个是string类型1、字符指针数组创建:char **parr = new char*[n];。 阅读全文

posted @ 2013-07-26 22:18 yi_meng 阅读(1983) 评论(0) 推荐(0) 编辑

C++STL概览
摘要:引言C++ STL可以分为标准容器,算法和函数对象,迭代器和分配器,利用C++标准程序库,可以大量减少我们的代码,提高代码的稳定性和健壮性。标准容器C++标准容器分为序列容器和关联容器,对于序列容器,C++提供的基本序列有vector 支持随机访问,不适合做插入和删除操作频繁的场景list 双向链表,适合做元素的插入和删除,不是随机访问deque 也是一个双端序列,但是经过优化,其双端操作效率类似list,随即访问效率接近vector。从它们出发,通过定义适当的借口,生成了stack 默认用deque实现queue 默认是deque实现priority_queue 默认是vector保存元素, 阅读全文

posted @ 2013-07-26 14:57 yi_meng 阅读(285) 评论(0) 推荐(0) 编辑

C++泛型句柄类
摘要:#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; 阅读全文

posted @ 2013-06-07 15:53 yi_meng 阅读(285) 评论(0) 推荐(0) 编辑

定义函数指针
摘要:---恢复内容开始---1。定义函数指针:typedef bool (*Comp) (const Sale_item&, cosnt Sale_item&);---恢复内容结束--- 阅读全文

posted @ 2013-06-07 15:51 yi_meng 阅读(117) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示