
数据结构与算法
wby93
这个作者很懒,什么都没留下…
展开
-
数据结构与算法--二叉树
二叉树遍历的非递归实现 1.前序遍历 二叉树前序遍历时,按照中、左、右的顺序遍历。非递归遍历时,新建一个栈,把头节点放入栈中,当栈不为空时,循环从栈里取节点,对于取出的每个节点,先把其右子树放入栈中,再把其左子树放入栈中。因为栈是先入后出的,后放入的左子树,就会先于右子树遍历,从而实现前序中、左、右顺序的遍历。 代码: public static void prePrint(TreeNode tr...原创 2019-11-24 10:36:41 · 197 阅读 · 0 评论 -
数据结构与算法-栈和队列
LeetCode_20 判断括号是否合法 Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. Input: “()[]{}” Output: true Input: “{[]}” Output: true 新建...原创 2019-11-02 16:27:02 · 154 阅读 · 0 评论 -
数据结构与算法--链表
LeetCode_206:逆序一个链表 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 该题目为反转一个链表,首先判断给定的链表head是否为null或者head.next是否为null,如果成立...原创 2019-10-27 13:27:17 · 203 阅读 · 0 评论