给定两个二叉树T1,T2判断T1是否是T2的子树
首先在T2中查找T1的根节点,如果找不到,
则T1不是T2的子树,如果能找到,我们可以
遍历T1,检查T1的每个结点是否对应的存在T2
中。
代码:
struct TreeNode
{
int data;
TreeNode* leftChild;
TreeNode* rightChild;
};
bool isExited(co...
分类:
其他好文 时间:
2014-09-09 12:52:58
阅读次数:
171
首先头文件,定义了链表的常用函数:
typedef struct node
{
int data;
struct node* next;
} Node;
class LinkListUtil
{
public:
LinkListUtil();
~LinkListUtil();
//create
Node* createByArray(int arr[], int len);
...
分类:
编程语言 时间:
2014-09-09 12:43:38
阅读次数:
281
gethostbyname()函数:通过名字地址获取相关信息的函数,返回的是一个struct hostent *,hostent是host entry的缩写,该结构记录主机的信息,包括主机名、别名、地址类型、地址长度和地址列表。就是结构指针,结构体的成员是这样定义的:1 struct hostent...
分类:
其他好文 时间:
2014-09-09 12:25:48
阅读次数:
252
#include #include #include #include int ticket_cnt = 20; /* 共有20张票 */typedef struct tag{ int s_id; pthread_mutex_t *s_p;}DATA,*pDATA;void* h...
分类:
编程语言 时间:
2014-09-09 12:13:48
阅读次数:
208
if-else 控制程序流程最基本的形式格式: if(boolean - expresion){ statement } 或 if(boolean - expresion){ statement }else{ stat...
分类:
编程语言 时间:
2014-09-09 11:52:28
阅读次数:
304
#include//系统当前日历的时间time_t time(time_t *time);//返回以tm结构存储的一个时间struct tm *localtime(const time_t *time);//返回字符串形式的时间表示char *asctime(const struct tm *ptr...
分类:
其他好文 时间:
2014-09-07 16:01:25
阅读次数:
208
重载操作符与转换--调用操作符和函数对象引言: 能够为类类型的对象重载函数调用操作符:一般为表示操作的类重载调用操作符!struct absInt{ int operator() (int val) { return val > 0 ? val : -val; }}...
分类:
编程语言 时间:
2014-09-07 15:59:35
阅读次数:
274
对于以下变量定义,以下表达式正确的是:( )struct node{ char s[10]; int k;}p[4];A.p->k=2 B.p[0].s="abc" C.p[0]->k=2 D.p->s='a'解答:这个题里,p是指针,指向p[0]...
分类:
其他好文 时间:
2014-09-07 14:43:05
阅读次数:
203
1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 struct BinaryTreeNode 9 { 10 int m_nValue; 11 ...
分类:
其他好文 时间:
2014-09-07 14:42:55
阅读次数:
252
1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct ListNode 8 { 9 //结点类型 10 int m_nValue; ...
分类:
其他好文 时间:
2014-09-07 10:55:04
阅读次数:
303