随笔分类 - 数据结构
摘要:思路: 嘻嘻,请读者自己手动模拟。博主这里不知道怎么说。 拓展: 该算法思路也适用于 (1)每层的结点个数 (2)树的最大宽度 (3)节点位于某一层 int height(BiTree T){ if(T==null) return 0; int front= 1, rear= 1;//front 出
阅读全文
摘要:思路: 标记一个结点的左右子树是否已经被访问过,叶子节点也进行标记 拓展: 遍历过程中读者会发现,某一时刻,从栈底到栈顶的元素刚好构成当前访问节点的到根节点的路径。利用这一特性可以实现两个算法:(1)根到某节点的路径(2)两个节点的最近公共祖先 typeDef struct{ BiTree t; i
阅读全文
摘要:思路:实际上是在先序遍历二叉树。递归一次,说明深入了一层。所以,在每次进入递归之时该层节点数++。 int count[MaxSize];//全局数组 int max = 1;全局变量 void width(BitNode T, int k){ if(T==null) return; count[k
阅读全文
摘要:void swap(BitTree b){ if(b){ swap(b lchild);//递归交换结点左孩子的左右子树。。。 swap(b rchild);//递归交换结点右孩子的左右子树。。 temp = b lchild;//交换左右子树 b lchild = b rchild; b rchi
阅读全文
摘要:int height(BitNode t){ if(t==null) return 0; else return 1+Max{height(t lchild),height(t rchild)}; } 您可能感兴趣的 非递归先序遍历二叉树 "https://www.cnblogs.com/Coeus
阅读全文
摘要:int Degree0(BitNode t){ if(t==null) return 0; if(t lchild==null&&t rchild==null) return 1; return Degree0(t lchild)+Degree0(t rchild); } 您可能感兴趣的 非递归先序
阅读全文
摘要:int Degree2(BitNode t){ if(t==null) return 0; if(t lchild!=null&&t rchild!=null) return 1+Degree2(t lchild)+Degree2(t rchild); return Degree2(t lchild
阅读全文
摘要:int Degree1(BitNode t){ if(t==null) return 0; if(t lchild==null&&t rchild!=null||t rchild==null&&t lchild!=null) return 1+Degree1(t lchild)+Degree1(t
阅读全文
摘要:如题: Pn(x) n=0的情况下为0 n=1的情况下为2x n 1的情况下为2xPn 1(x) 2(n 1)Pn 2(x) 思路:博主想了半天不知道咋说,但是这是一种递归思想。还请读者好好体会 func(Tree T){ //本程序需要的数据结构 struct Stack{ int n; int
阅读全文
摘要:如果第一遍看不懂不要紧,请手动模拟体会。这个方法是设置最近访问节点,另解参考博主博文版本二 func(Tree T){ if(T==NULL){ printf("树空"); return } Stact S; TreeNode r=NULL;//用于标记是否是从右子树返回的,读者手动模拟一遍就知道了
阅读全文
摘要:请读者对比学习本博客非递归先序遍历二叉树 "https://www.cnblogs.com/Coeus P/p/9353186.html" func(Tree T){ if(T==NULL){ printf("树空"); return } Queue q; EnQueue(q,T); while(!
阅读全文
摘要:读者手动模拟时需注意叶子节点的左右子树进入循环的情况 func(Tree T){ if(T==NULL){ printf("树空"); return; } Stack S; while(T!=NULL||!IsEmpty(S)){ if(T){ push(S,T); T=T lchild; } el
阅读全文
摘要:func(Tree T){ if(T==NULL){ printf("树空"); return; } Stack S; push(S,T); while(!IsEmpty(S)){ pop(S,T); visit(T); if(T rchild) push(S,T rchild); if(T lch
阅读全文
摘要:public class nonRecursiveMergeSort { public static void main(String[] args) { int[] list = {8,4,3,6,9}; MergeSort(list); for(int num:list) System.out.
阅读全文
摘要:public class MergeSort { public static void mergeSort(int [] list){ if(list.length 1){ int [] firstHalf = new int[list.length/2]; System.arraycopy(lis
阅读全文
摘要:public class InsertSort { public static void insertSort(int [] list){ for(int i=2;icurrentElement;k ){ list[k+1] = list[k]; } list[k+1] = currentEleme
阅读全文
摘要:public class BucketSort { public static void main(String[] args) { int[] list = {1000, 192, 221, 12, 23}; print(list); System.out.println(); bucketSor
阅读全文
摘要:public class HeapSort { public static void HeapAdjust(int[] num, int s, int m){ int temp = num[s]; for(int i=2 s;i=num.length) return false; else retu
阅读全文
摘要:public class BubbleSort { public static void bubbleSort(int [] list){ boolean needNextPass = true; for(int i=1;ilist[j+1]){ int temp = list[j]; list[j
阅读全文
摘要:public class BubbleSort_Two { public static void bubbleSort_Two(int[] list){ //j在最外层定义 boolean needNextPass = true; for(int i=0,j;ilist[j+1]){ int tem
阅读全文

浙公网安备 33010602011771号