
栈和队列
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
PAT乙级B1025 反转链表 (25)
给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。 输入格式: 每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数正整数N(<= 10^5^)、以及正整数K(<=N),即要求反转的子链结点...原创 2018-07-23 21:22:33 · 248 阅读 · 0 评论 -
PAT甲级A1014 Waiting in Line (30)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are: The space...原创 2018-07-29 16:21:24 · 184 阅读 · 0 评论 -
PAT甲级A1020 Tree Traversals (25)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the cor...原创 2018-08-07 22:28:58 · 158 阅读 · 0 评论 -
LeetCode--20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of b...原创 2018-06-11 21:43:28 · 126 阅读 · 0 评论 -
PAT甲级A1051 Pop Sequence (25 分)
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t...原创 2019-01-19 16:48:53 · 347 阅读 · 0 评论 -
PAT甲级A1086 Tree Traversals Again (25 分)
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...原创 2019-02-21 16:04:36 · 162 阅读 · 0 评论 -
PAT甲级A1123 Is It a Complete AVL Tree (30 分)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is...原创 2019-03-08 15:43:01 · 159 阅读 · 0 评论