![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 67
hachyli
这个作者很懒,什么都没留下…
展开
-
二叉树的非递归遍历
二叉树是一种非常重要的数据结构,很多其它数据结构都是基于二叉树的基础演变而来的。对于二叉树,有前序、中序以及后序三种遍历方法。因为树的定义本身就是递归定义,因此采用递归的方法去实现树的三种遍历不仅容易理解而且代码很简洁。而对于树的遍历若采用非递归的方法,就要采用栈去模拟实现。在三种遍历中,前序和中序遍历的非递归算法都很容易实现,非递归后序遍历实现起来相对来说要难一点。一.前序遍历转载 2014-07-22 09:12:06 · 485 阅读 · 0 评论 -
Reverse Nodes in k-Group leetcode
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-09-01 22:01:16 · 362 阅读 · 0 评论 -
Sort List leetcode
Sort a linked list in O(n log n) time using constant space complexity.原创 2014-09-02 14:16:45 · 287 阅读 · 0 评论 -
堆排序
利用最大堆实现。最大堆:最大堆性质是除了根结点意外的所有结点 i 都要满足A[parent[i]] >= A[i]需要利用到的一个性质:当用数组表示存储n个元素的堆时,叶结点的下标分别是n/2, n/2+1, n/2 + 2, ......,n - 1. (下标从0开始)需要用到的函数有:void max_heapify(int *a, int i) //通原创 2014-09-22 20:10:59 · 375 阅读 · 0 评论 -
Clone Graph leetcode
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.原创 2014-09-10 16:40:15 · 355 阅读 · 0 评论 -
Maximum Depth of Binary Tree leetcode
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Anwser 1 : DFSclass Solut原创 2014-08-13 09:06:32 · 363 阅读 · 0 评论 -
leetcode Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2014-08-01 15:43:17 · 312 阅读 · 0 评论 -
leetcode Linked List Cycle II 单链表中的环问题集锦
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?如何判断一个单链表中有环?Linked List Cycle IIGiven a linked list,原创 2014-08-02 08:31:20 · 543 阅读 · 1 评论 -
二叉查找树 红黑树 2-3-4树 定义
二叉查找树:原创 2014-07-26 11:03:42 · 720 阅读 · 0 评论 -
C++ STL中哈希表 hash_map介绍
0 为什么需要hash_map用过map吧?map提供一个很常用的功能,那就是提供key-value的存储和查找功能。例如,我要记录一个人名和相应的存储,而且随时增加,要快速查找和修改:岳不群-华山派掌门人,人称君子剑张三丰-武当掌门人,太极拳创始人东方不败-第一高手,葵花宝典...这些信息如果保存下来并不复杂,但是找起来比较麻烦。例如我要找"张三丰"的信转载 2014-07-25 21:50:50 · 379 阅读 · 0 评论 -
B-树和B+树的应用:数据搜索和数据库索引
B-树转载 2014-07-25 20:46:05 · 408 阅读 · 0 评论 -
Reorder List leetcode
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to原创 2014-09-02 19:31:00 · 418 阅读 · 0 评论