上一页 1 2 3 4 5 6 7 8 9 10 ··· 16 下一页

2014年5月22日

二叉树非递归遍历 重点是后序

摘要: 二叉树是一种非常重要的数据结构,很多其它数据结构都是基于二叉树的基础演变而来的。对于二叉树,有前序、中序以及后序三种遍历方法。因为树的定义本身就是递归定义,因此采用递归的方法去实现树的三种遍历不仅容易理解而且代码很简洁。而对于树的遍历若采用非递归的方法,就要采用栈去模拟实现。在三种遍历中,前序和中序... 阅读全文

posted @ 2014-05-22 18:05 berkeleysong 阅读(129) 评论(0) 推荐(0) 编辑

前序中序后序遍历非递归实现

摘要: #include#include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():val(0),lef... 阅读全文

posted @ 2014-05-22 17:58 berkeleysong 阅读(263) 评论(0) 推荐(0) 编辑

用递归做的前序中序后序遍历

摘要: #include#include#include#include#includeusing namespace std;class node{public: int val; node* left; node* right; node():val(0),left(NULL),... 阅读全文

posted @ 2014-05-22 16:14 berkeleysong 阅读(157) 评论(0) 推荐(0) 编辑

2014年5月21日

不同元素的排列与组合

摘要: #include#include#include#include#includeusing namespace std; vector > ret;vector sub;int num = 0;void helper(int* str, int n,int i) ///递归求组合{ if(i ==... 阅读全文

posted @ 2014-05-21 17:59 berkeleysong 阅读(195) 评论(0) 推荐(0) 编辑

两种字符串逆序的方法

摘要: #include#include#include#includeusing namespace std;void helper(char* str) ///用指针实现,注意strlen的用法,并且没有动最后的\0{ int len = strlen(str); int pleft = 0; i... 阅读全文

posted @ 2014-05-21 13:22 berkeleysong 阅读(164) 评论(0) 推荐(0) 编辑

递归合并链表~

摘要: #include#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;... 阅读全文

posted @ 2014-05-21 12:36 berkeleysong 阅读(237) 评论(0) 推荐(0) 编辑

使用map做数组与链表去重

摘要: #include#includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;... 阅读全文

posted @ 2014-05-21 10:51 berkeleysong 阅读(490) 评论(0) 推荐(0) 编辑

链表有环检测,环长度,环开始的地方

摘要: #includeusing namespace std;class node{public: node():value(0),next(NULL){} ~node(){} int value; node* next;};///be careful this ;node* cr... 阅读全文

posted @ 2014-05-21 09:43 berkeleysong 阅读(191) 评论(0) 推荐(0) 编辑

2014年5月20日

private, public, protected 访问标号的访问权限

摘要: 忘记出处了第一:private, public, protected 访问标号的访问范围。private:只能由1.该类中的函数、2.其友元函数访问。不能被任何其他访问,该类的对象也不能访问。protected:可以被1.该类中的函数、2.子类的函数、以及3.其友元函数访问。但不能被该类的对象访问。... 阅读全文

posted @ 2014-05-20 15:30 berkeleysong 阅读(138) 评论(0) 推荐(0) 编辑

友元函数 C++

摘要: #include#includeusing namespace std;class Text{public: Text():a(1){}private: int a; void display(){ cout<< "hello world"<<endl;} friend vo... 阅读全文

posted @ 2014-05-20 14:46 berkeleysong 阅读(203) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 16 下一页

导航