文章分类 -  数据结构

摘要:一、单向链表 假设单向链表的节点定义如下: 1、往链表结尾添加一个节点: 关键在于函数的第一个传入参数是一个指向指针的指针。当我们往空链表插入节点时,新插入的节点就是链表的头指针,由于此时会改动头指针,因此必须把pHead参数设置为指向指针的指针,否则出了这个函数pHead仍然是一个空指针。 如下面 阅读全文
posted @ 2019-07-19 11:47 琴影 阅读(151) 评论(0) 推荐(0) 编辑
摘要:3.堆的操作的复杂度 堆的两种操作所花的时间都和树的深度成正比。因此,如果一共有n个元素,那么每个操作可以在O(logN)的时间内完成。 阅读全文
posted @ 2016-08-23 23:22 琴影 阅读(120) 评论(0) 推荐(0) 编辑
摘要:Given an infinite number line from -INFINITY to +INFINITY and we are on zero. We can move n steps either side at each n’th time. Examples: This proble 阅读全文
posted @ 2016-08-06 23:22 琴影 阅读(161) 评论(0) 推荐(0) 编辑
摘要:问题 对于普通的二叉树,如何找到两个给定节点之家的距离?距离是指连接两个节点需要的最小的边的条数。 例如下面的二叉树: 这个问题很全面的考察了二叉树相关的知识,建议大家先尝试自己解决~ 分析 假设给定的节点为node1, node2,可以分为下面两种情况: 1) node1是node2的祖先节点或孩 阅读全文
posted @ 2016-08-06 16:49 琴影 阅读(1907) 评论(0) 推荐(0) 编辑
摘要:The article describes an approach to solving the problem of finding the LCA of two nodes in a tree by reducing it to a RMQ problem. Lowest Common Ance 阅读全文
posted @ 2016-07-30 19:49 琴影 阅读(292) 评论(0) 推荐(0) 编辑
摘要:Given values of two nodes in a Binary Search Tree, write a c program to find the Lowest Common Ancestor (LCA). You may assume that both the values exi 阅读全文
posted @ 2016-07-30 19:45 琴影 阅读(119) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree (not a binary search tree) and two values say n1 and n2, write a program to find the least common ancestor. Following is definitio 阅读全文
posted @ 2016-07-30 19:27 琴影 阅读(304) 评论(0) 推荐(0) 编辑