随笔分类 - 数据结构
摘要:1 #include 2 using namespace std; 3 4 typedef struct TBTNode 5 { 6 char data; 7 int ltag,rtag; 8 struct TBTNode * lchild; 9 ...
阅读全文
摘要:#include #define maxSize 5using namespace std;typedef struct BTNode{ char data; struct BTNode * lchild; struct BTNode * rchild;}BTNode;BTNode...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 typedef struct BTNode 5 { 6 char data; 7 struct BTNode * lchild; 8 struct BTNode * rchild; 9 }BTN...
阅读全文
摘要:列出n以内的质子数 1 #include 2 #include 3 using namespace std; 4 5 int* Sieve(int n, int &length) 6 { 7 int *A,*B; 8 int p=0,j=0,i=0,k=0,q=0; 9 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 int gcd(int m , int n) 5 { 6 int r; 7 while(n!=0) 8 { 9 r = m%n;10 m = n;11 ...
阅读全文
摘要:性质一:在二叉树的第i层上至多有2^(i-1)个结点(i>=1)性质二:深度为k的二叉树至多有2^(k-1)个结点(k>=1)性质三:对任意一颗二叉树T,若终端结点数为n0,而其度数为2的结点数为n2,则 n0=n2+1满二叉树:深度为k,且有2^(k-1)个结点的二叉树。 在满二叉树中,每...
阅读全文
摘要:1 #include 2 #define MAXSIZE 50 3 #define QUEUEELEMENTTYPE int 4 using namespace std; 5 6 struct SeqQueue 7 { 8 QUEUEELEMENTTYPE element[MAXSIZ...
阅读全文
摘要:循环队列是队列的一种顺序表示和实现的方法。与顺序栈类似,在队列的顺序存储结构中,用一组地址连续的存储单元依次存放从队头到队尾的元素,如一维数组Queue[MAXSIZE]。此外,由于队列中队头和队尾的位置都是动态变化的,因此需要附设俩个指针front和rear,分别指示队头元素和为元素在数组中的位置...
阅读全文
摘要:1 #include 2 #define QUEUEELEMENTTYPE int 3 using namespace std; 4 5 /*结点*/ 6 typedef struct Node 7 { 8 QUEUEELEMENTTYPE data; /*数据域*/ ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 struct Node 5 { 6 int data; 7 Node *next; 8 }; 9 10 /*初始化链栈*/11 void InitChainStack(Node *top)12 {13 ...
阅读全文
摘要:1 #include 2 #define STACKSIZE 50/*设栈中元素个数为50个*/ 3 using namespace std; 4 5 struct SeqStack 6 { 7 int elem[STACKSIZE]; 8 int top; ...
阅读全文
摘要:LinearList.cpp 1 /* 2 458043535@qq.com 3 xxdfly 4 */ 5 #include "LinearList.h" 6 7 //构造函数 8 LinearList::LinearList() 9 { 10 head...
阅读全文
摘要:1 #include 2 3 using namespace std; 4 5 struct Node{ 6 int data; 7 Node *next; 8 }; 9 10 Node* InitNodeList(){11 Node *node=0;//定义一个空指...
阅读全文
摘要:常出现在伪代码中:向上取整 ⌈59/60⌉=1 ⌈-59/60⌉=0向下取整 ⌊59/60⌋=0 ⌊-59/60⌋=-1
阅读全文
摘要:一、概念与图论中的“度”不同,树的度是如下定义的:有根树T中,结点x的子女数目称为x的度。也就是:在树中,结点有几个分叉,度就是几。一个有用的小公式:树中结点数 = 总分叉数 +1。(这里的分叉数就是所有结点的度之和)二、度的计算1.设树T的度为4,其中度为1,2,3,4的节点个数分别为4,2,1,...
阅读全文