数据结构之PTA
文章平均质量分 85
尼亚3c
这个作者很懒,什么都没留下…
展开
-
5-2 一元多项式的乘法与加法运算 (20分) (单向链表)
设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。零多项式应输出0 0。输入样例:原创 2017-03-08 19:08:36 · 327 阅读 · 0 评论 -
04-树6 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 less than the node's key.原创 2017-03-26 10:14:59 · 257 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树 (25分)
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数NN (\le 10≤10)和LL,分别是每原创 2017-03-25 20:20:05 · 320 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集 (30分)
本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST原创 2017-03-25 19:35:12 · 1978 阅读 · 0 评论 -
02-线性结构4 Pop Sequence (25分) (栈)
Given a stack which can keep MM numbers at most. Push NN numbers in the order of 1, 2, 3, ..., NN and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequ原创 2017-03-09 14:40:20 · 189 阅读 · 0 评论 -
02-线性结构3 Reversing Linked List (25分)
Given a constant KK and a singly linked list LL, you are supposed to reverse the links of every KK elements on LL. For example, given LL being 1→2→3→4→5→6, if K = 3K=3, then you must outpu原创 2017-03-09 13:58:08 · 182 阅读 · 0 评论 -
03-树3 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原创 2017-03-18 18:34:54 · 229 阅读 · 0 评论 -
02-线性结构1 两个有序链表序列的合并 (15分) (单向链表)
本题要求实现一个函数,将两个链表表示的递增整数序列合并为一个非递减的整数序列。函数接口定义:List Merge( List L1, List L2 );其中List结构定义如下:typedef struct Node *PtrToNode;struct Node { ElementType Data; /* 存储结点数据 */ PtrToNode原创 2017-03-08 21:34:38 · 909 阅读 · 0 评论 -
03-树2 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 first line give原创 2017-03-18 12:30:06 · 226 阅读 · 0 评论 -
03-树1 树的同构 (25分)
给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。图1图2现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树原创 2017-03-18 11:38:58 · 179 阅读 · 0 评论 -
04-树5 Root of AVL Tree (25分)
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原创 2017-03-26 14:17:14 · 373 阅读 · 0 评论