11 2013 档案

摘要:struct node{Node Left;Node Right;int MaxLeft;//左子树到该节点的最长距离int MaxRight;//右子树到该节点的最长距离char chValue;};void FindMaxLen(Node T){int tmpMax = 0;if (NULL == T){return;}if (NULL == T->Left){T->MaxLeft = 0;}if (NULL == T->Right){T->MaxLeft = 0;}if (NULL != T->Left){FindMaxLen(T->Left);}if 阅读全文
posted @ 2013-11-12 11:04 SLVR 阅读(146) 评论(0) 推荐(0) 编辑
摘要:要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)typedef int (*fptrSum)(int n);struct M{fptrSum Sum;};struct M A[2];int Sum0(int n){return n;}int Sum1(int n){return A[!!(n-1)].Sum(n-1) + n;}int main(){int val = 0;int n = 100;A[0].Sum = Sum0;A[1].Sum = Sum1;val = A[1].Sum(n);printf("%d& 阅读全文
posted @ 2013-11-09 10:49 SLVR 阅读(143) 评论(0) 推荐(0) 编辑
摘要:这个题目需要将非递归中序遍历中的入栈方法稍微改进一下1、对任意节点Cur若不为空入栈,并将其左孩子置为Cur,直到Cur为空;2、判断栈是否为空,若不为:将栈顶元素赋给Cur(但并不出栈),若Cur的右孩子为空或Pre与Cur的右孩子值相等,则判断此时栈中所有元素的和是否与特定的sum值相等,并将栈顶元素Pop给Pre;将Cur的右孩子置为Cur;3、直到Cur为空且栈为空时,遍历结束ElementType SumOfStack(Stack St){ int sum, i; for (i=0,sum=0; icount; i++) { sum += St->Elment[i]->E 阅读全文
posted @ 2013-11-05 16:06 SLVR 阅读(148) 评论(0) 推荐(0) 编辑
摘要:穷举法:int MaxSubArraySum(int a[], int n){int i, j, MaxSum = 0, tmpSum, cnt;for (i=1; i<=n; i++){for (j=0; j+i<=n; j++){cnt = 0;tmpSum = 0;while (cnt < i){tmpSum += a[j+cnt];cnt++;}if (MaxSum < tmpSum){MaxSum = tmpSum;}}}return MaxSum;}通过循环嵌套,控制步长,求出所有的子数组的值找出规律法:int MaxSub(int a[], int n){ 阅读全文
posted @ 2013-11-02 17:21 SLVR 阅读(161) 评论(0) 推荐(0) 编辑
摘要:题目要求是转换,所以不难想到二叉查找树的数据结构和双向链表是一样的,根据二叉查找树的性质,其中序遍历的数据就是由小到大排序,所以只需在其非递归的中序遍历代码中加入一些代码即可实现转换。详细代码见project/树文件夹中代码,其中包含了三种基本遍历和层序遍历的非递归实现,都需要使用到栈。三种基本遍历:http://www.cnblogs.com/dolphin0520/archive/2011/08/25/2153720.html下面贴出基本功能代码:typedef int ElementType;typedef struct TreeNode *Position;typedef struct 阅读全文
posted @ 2013-11-02 10:43 SLVR 阅读(188) 评论(0) 推荐(0) 编辑