Data Structure
cfzjxz
这个作者很懒,什么都没留下…
展开
-
习题集1.16
#include int main(){ int x,y,z ; cin >> x >> y >> z ; if (x>y) { if (y>z) cout<<x<<y<<z<<endl; else if (x>z) cout<<x<<z<<y<<endl; else cout<<z<<x<<y<<end原创 2012-01-17 14:30:10 · 373 阅读 · 0 评论 -
习题6.20,习题6.21
习题6.20 同19,采用完全二叉数组存储方式 ////////////////////////////////////////////////////////////////////////////6.21 打印前序void pretravlesz(btnode bt[],int n){ BiTree *T ; T = (BiTree *)calloc(n,siz原创 2012-02-27 12:08:46 · 592 阅读 · 0 评论 -
习题6.22 习题6.23 习题6.24 习题6.31
习题6.22 略习题6.23 略习题6.24 习题6.31满二叉树后序序列转换为先序序列//6.31void post2pre(Xtype post[],Xtype pre[],int postart ,int poend ,int pestart,int peend ){ int half ; if (poend >= postart) { pre[原创 2012-02-27 17:02:12 · 476 阅读 · 0 评论 -
习题6.19
////////////////////////////////////////////////////////////////////////////6.19 前序遍历非递归算法void pretravle(BiTree T){ BiTree bt = T ; SqStack stk; InitStack(&stk) ; while(!StackEmpty(stk)原创 2012-02-27 11:37:12 · 359 阅读 · 0 评论 -
习题6.18
//6.18 打印所有祖先结点void printances (BiTree T,char x){ int i = 0 ; BiTree array[20] ,bt ,pre ; bt = T ; pre = null ; while (i >0 || bt != null) { if (bt != null) { array[++i] = bt原创 2012-02-27 11:30:10 · 426 阅读 · 0 评论 -
习题6.37
//6.37前序和中序序列建立二叉链表BiTree buildbyprein(char pre[],char in[],int L1,int H1 ,int L2,int H2 ){ BiTree T; if (L1 <= H1) { T = (BiTree)malloc(sizeof(BiTNode)) ; T -> data = pre[L1] ; for原创 2012-02-28 11:18:54 · 409 阅读 · 0 评论 -
习题6.44
///////////////////////////////////////////////////////////////////////////6.44建立叶子链表void buildyezi(BiTree T ,BiTree &pre ,BiTree &head){ if (T != null) { if (T -> lchild == NULL && T ->原创 2012-02-28 11:19:51 · 334 阅读 · 0 评论 -
习题6.60
打印某一节点路径void printroute(BiTree T,Xtype ttt) { BiTree bt ,pre = NULL; SqStack stk ; InitStack(&stk) ; bt = T; // Push(&stk,bt) ; while(bt != NULL || !StackEmpty(stk)) { if (bt != N原创 2012-03-06 11:47:05 · 453 阅读 · 0 评论 -
string类模式匹配KMP 数组版本
int *findNext(char *p){ int i = 0; int k = -1; int m = strlen(p); if (m <= 0) return NULL; int *next = new int[m]; next[0] = -1; while (i < m) { while (k >= 0 && p[i] != p[k])原创 2012-05-16 11:53:33 · 771 阅读 · 0 评论 -
关于图论的一些小结 (一)
图论的主要算法:1.图的广度优先遍历:–先遍历较近的点,一层层向外扩展–常用队列存储当前正被展开的点伪代码: Q={s}; 标记s为己访问; while (Q非空) { 取Q队首元素u; 所有与u相邻且未被访问的点进入队列; 标记u为已访问; } 一些应用:①无向图的连通分量原创 2012-10-22 08:19:30 · 430 阅读 · 0 评论 -
习题6.15查找二叉树结点公共祖先
//6.15 公共祖先 结点/*查找a,b的最近公共祖先,root为根节点,out为最近公共祖先的指针地址*/ int FindNCA(BiTree root, char a, char b, BiTree &out) { if( root == null ) { return 0; }转载 2012-02-25 21:33:51 · 505 阅读 · 0 评论 -
习题6.8,习题6.9,习题6.10 习题6.14
习题6.8 层次遍历习题6.9同习题6.7习题6.10 前序遍历+层次遍历习题6.11略习题6.14 //6.14 孩子兄弟链表深度int depthbro(BiTree T){ if (T != NULL ) { if (T -> lchild != NULL) { if (T -> rchild == NULL) retur原创 2012-02-25 20:28:42 · 1476 阅读 · 0 评论 -
习题集1.20
#include using namespace std;const int numbers = 10 ;int main(){ int x0; int temp ; int sum = 0; int x = 1 ; int value ; cout<<"输入X0的值"<<endl; cin>>x0 ; cout<<"输入10个多项式系数"<<e原创 2012-01-17 16:02:45 · 504 阅读 · 0 评论 -
习题集1.17
#include #include using namespace std;int Fibonacci(int k,int m);int main(){ int m,k; cout<<"k阶斐波那契"<<" "; cin>>k; cout<<"第m项为"<<" "; cin>>m; cout<<"结果是"<<endl; cout<<原创 2012-01-17 15:15:20 · 421 阅读 · 0 评论 -
习题集1.19
#include using namespace std;const int arraysize = 11 ; //第11个数溢出int array[arraysize] ;int cacu(int (&array)[arraysize]);int main(){ cacu(array) ; for (int k =0 ;k<arraysize ;++原创 2012-01-17 15:49:12 · 462 阅读 · 0 评论 -
习题6.4
int countleaves (BiTree T){ if (T != NULL) { if (T ->lchild != NULL && T -> rchild != NULL) { return (countleaves(T ->lchild) + countleaves(T -> rchild) ) ; } else { if (T原创 2012-02-25 15:21:57 · 387 阅读 · 0 评论 -
习题6.1
/////////////////////////////////////////////////////////////////////////////习题6.1 二叉树求值int value (BiTree T){ int val ; if (T -> lchild == NULL && T ->rchild == NULL) { return T ->data原创 2012-02-25 14:55:39 · 621 阅读 · 0 评论 -
习题6.2
///习题6.2 由二叉树得到中缀表达式,添括号int comp (char opt1,char opt2 ){ if (opt1 == '*' || opt1 == '/') { if (opt2 == '*' || opt2 == '/' ) return 0 ; else if (opt2 == '+' || opt2 == '-' ) {原创 2012-02-25 14:56:26 · 625 阅读 · 0 评论 -
习题6.6
///习题6.6 判定完全二叉树int judgewq (BiTree T){ BiTree bt = T ; LinkQueue btqu ; InitQueue(&btqu) ; int flag = 0 ; // if (bt != NULL) { EnQueue(&btqu , bt) ; while(!QueueEmpty(btqu) )原创 2012-02-25 17:23:56 · 6317 阅读 · 0 评论 -
习题6.7
////////////////////////////////////////////////////////////////////////////习题6.7 由完全二叉树数组 建立二叉链表BiTree buildec2(char A[] ,int N,int i){ BiTree T = NULL; if (i <= N) { T = (BiTree) mall原创 2012-02-25 19:17:39 · 445 阅读 · 0 评论 -
习题6.3
/////////////////////////////////////////////////////////////////////////////习题6.3void nodesnum (BiTree T ,int &n0 , int &n1 , int &n2){ if (T) { if ( T -> lchild != NULL && T -> rchild原创 2012-02-25 15:13:47 · 531 阅读 · 0 评论 -
习题6.5
///习题6.5void buildptree (const int L[],const int R[] ,int N ,int p[]){ for (int i = 1 ; i <= N ; i++) { if (L[i] != 0) { p[L[i]] = i ; } if (R[i] != 0) { p[R[i]] = i原创 2012-02-25 15:54:01 · 384 阅读 · 0 评论 -
关于图论的一些小结 (二)
连通分量求法:强连通分量一定是图的深搜树的一个子树。对于DAG,两次DFS,第一次DFS原图,第二次DFS反向图求得各个强连通DFS一种很文艺的写法TOJ 2233题/* 求强连通分量,做法:先对图进行DFS,记录每个节点的结束时间f[i] * 然后对反图按照f[i]从大到小的顺序对反图进行DFS,在中间过程中记录每个连通分量中最小的值,并将其赋值给其根节点 * 仍原创 2012-10-23 14:59:53 · 425 阅读 · 0 评论