PTA习题记录
四月~
新手
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
6-9 Sort Three Distinct Keys(20 分)
6-9 Sort Three Distinct Keys(20 分)Suppose you have an array of N elements, containing three distinct keys, "true", "false", and "maybe". Given an O(N) algorithm to rearrange the list so that all "fals...原创 2018-02-15 14:37:39 · 1511 阅读 · 1 评论 -
6-16 Shortest Path [3](25 分)
6-16 Shortest Path [3](25 分)Write a program to not only find the weighted shortest distances, but also count the number of different minimum paths from any vertex to a given source vertex in a digraph...原创 2018-02-25 10:53:23 · 2755 阅读 · 0 评论 -
6-15 Iterative Mergesort(25 分)
6-15 Iterative Mergesort(25 分)How would you implement mergesort without using recursion?The idea of iterative mergesort is to start from N sorted sublists of length 1, and each time to merge a pair of...原创 2018-02-24 13:43:31 · 2746 阅读 · 0 评论 -
6-10 Strongly Connected Components(30 分)
6-10 Strongly Connected Components(30 分)Write a program to find the strongly connected components in a digraph.Format of functions:void StronglyConnectedComponents( Graph G, void (*visit)(Vertex V) );...原创 2018-02-23 20:05:33 · 2024 阅读 · 0 评论 -
6-14 Count Connected Components(20 分)
6-14 Count Connected Components(20 分)Write a function to count the number of connected components in a given graph.Format of functions:int CountConnectedComponents( LGraph Graph );where LGraph is def...原创 2018-02-22 15:47:35 · 2553 阅读 · 0 评论 -
6-13 Topological Sort(25 分)
6-13 Topological Sort(25 分)Write a program to find the topological order in a digraph.Format of functions:bool TopSort( LGraph Graph, Vertex TopOrder[] );where LGraph is defined as the following:type...原创 2018-02-21 18:07:46 · 1025 阅读 · 0 评论 -
6-12 Shortest Path [2](25 分)
6-12 Shortest Path [2](25 分)Write a program to find the weighted shortest distances from any vertex to a given source vertex in a digraph. It is guaranteed that all the weights are positive.Format of ...原创 2018-02-19 21:36:57 · 1276 阅读 · 0 评论 -
6-11 Shortest Path [1](25 分)
6-11 Shortest Path [1](25 分)Write a program to find the unweighted shortest distances from any vertex to a given source vertex in a digraph.Format of functions:void ShortestDist( LGraph Graph, int dis...原创 2018-02-18 21:29:02 · 2262 阅读 · 1 评论 -
6-1 Deque(25 分)
6-1 Deque(25 分)A "deque" is a data structure consisting of a list of items, on which the following operations are possible:Push(X,D): Insert item X on the front end of deque D.Pop(D): Remove the front...原创 2018-02-11 11:07:47 · 2206 阅读 · 0 评论 -
6-2 Two Stacks In One Array(20 分)
6-2 Two Stacks In One Array(20 分)Write routines to implement two stacks using only one array. Your stack routines should not declare an overflow unless every slot in the array is used.Format of functi...原创 2018-02-11 11:11:20 · 1773 阅读 · 0 评论 -
6-3 Add Two Polynomials(20 分)
6-3 Add Two Polynomials(20 分)Write a function to add two polynomials. Do not destroy the input. Use a linked list implementation with a dummy head node. Note: The zero polynomial is represented by an ...原创 2018-02-11 11:14:28 · 1905 阅读 · 1 评论 -
6-4 Reverse Linked List(20 分)
6-4 Reverse Linked List(20 分)Write a nonrecursive procedure to reverse a singly linked list in O(N) time using constant extra space.Format of functions:List Reverse( List L );where List is defined as...原创 2018-02-11 11:16:17 · 2981 阅读 · 0 评论 -
6-5 Evaluate Postfix Expression(25 分)
6-5 Evaluate Postfix Expression(25 分)Write a program to evaluate a postfix expression. You only have to handle four kinds of operators: +, -, x, and /.Format of functions:ElementType EvalPostfix( char...原创 2018-02-12 15:46:45 · 1905 阅读 · 0 评论 -
6-6 Level-order Traversal(25 分)
6-6 Level-order Traversal(25 分)Write a routine to list out the nodes of a binary tree in "level-order". List the root, then nodes at depth 1, followed by nodes at depth 2, and so on. You must do this ...原创 2018-02-13 12:09:54 · 2338 阅读 · 0 评论 -
6-7 Isomorphic(20 分)
6-7 Isomorphic(20 分)Two trees, T1 and T2, are isomorphic if T1 can be transformed into T2 by swapping left and right children of (some of the) nodes in T1. For instance, the two trees in Figure 1 are ...原创 2018-02-14 00:27:06 · 3433 阅读 · 0 评论 -
6-8 Percolate Up and Down(20 分)
6-8 Percolate Up and Down(20 分)Write the routines to do a "percolate up" and a "percolate down" in a binary min-heap.Format of functions:void PercolateUp( int p, PriorityQueue H );void PercolateDown(...原创 2018-02-14 22:43:03 · 1246 阅读 · 0 评论 -
6-17 Shortest Path [4](25 分)
6-17 Shortest Path [4](25 分)Write a program to find the weighted shortest distances from any vertex to a given source vertex in a digraph. If there is more than one minimum path from v to w, a path wi...原创 2018-02-25 12:42:13 · 1107 阅读 · 0 评论
分享