![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
啊咧咧-
这个作者很懒,什么都没留下…
展开
-
浙大PAT:堆的操作集
7-5 堆中的路径 (25分) 将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。 输入格式: 每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。 输出格式: 对输入中给出的每个下标i,在一行...原创 2020-04-26 19:12:01 · 296 阅读 · 0 评论 -
构建完全二叉搜索树
7-7 Complete Binary Search Tree (30分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys le...原创 2020-04-24 15:06:33 · 647 阅读 · 0 评论 -
C语言实现平衡二叉树全过程
Root of AVL Tree 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 on...原创 2020-04-23 23:36:44 · 1518 阅读 · 0 评论 -
浙大PAT:是否是同一颗二叉排序树
7-4 是否同一棵二叉搜索树 (25分) 给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。 输入格式: 输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤10)和L...原创 2020-04-23 15:53:28 · 125 阅读 · 0 评论 -
浙大PAT:7-5 Tree Traversals Again (25分)
7-5 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 fro...原创 2020-04-18 22:09:52 · 264 阅读 · 0 评论 -
浙大PAT遍历叶子结点:7-4 List Leaves
7-4 List Leaves (25分) Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one test case. For each case, the...原创 2020-04-11 23:22:40 · 185 阅读 · 0 评论 -
浙大PAT:树的同构
7-3 树的同构 (25分) 给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。 图1 图2 现给定两棵树,请你判断它们是否是同构的。 输入格式: 输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N (≤1...原创 2020-04-11 11:55:29 · 161 阅读 · 0 评论 -
浙大PAT出栈序列:7-3 Pop Sequence
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 the...原创 2020-04-10 22:32:55 · 474 阅读 · 0 评论 -
浙大PAT反转链表:7-2 Reversing Linked List
7-2 Reversing Linked List (25分) Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you ...原创 2020-04-04 17:14:06 · 860 阅读 · 0 评论 -
浙大PAT最大子列和:Maximum Subsequence Sum
#include <iostream> int MaxSubSeqSum(int A[], int n, int &first, int &last) { int ThisSum(0),MaxSum(A[0]); int i(0),first_1(0); for(;i<n;i++) { ThisSum+=A[i]; if(This...原创 2020-04-02 13:56:28 · 105 阅读 · 0 评论 -
浙大PAT:一元多项式的加法与乘法
PAT:一元多项式的加法与乘法 #include <stdio.h> #include <stdlib.h> typedef struct Node{ int xs; int zs; struct Node* next; }Node,*List; void Init(List *L){ *L = (List)malloc(sizeof(N...原创 2020-04-02 11:51:27 · 185 阅读 · 0 评论