数据结构
沿麓
coder
展开
-
线性表的单链表存储结构
#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0typedef int ElemType;typedef int Status;typedef struct LNode{ ElemType data; struct LNode *next;}LNode,*Link...原创 2018-10-15 19:54:38 · 1407 阅读 · 0 评论 -
6-3 邻接表存储图的广度优先遍历 (20 分)
试实现邻接表存储图的广度优先遍历。函数接口定义:void BFS ( LGraph Graph, Vertex S, void (*Visit)(Vertex) );其中LGraph是邻接表存储的图,定义如下:/* 邻接点的定义 */typedef struct AdjVNode *PtrToAdjVNode; struct AdjVNode{ Vertex Ad...原创 2018-12-19 17:18:47 · 3238 阅读 · 0 评论 -
6-2 图的深度遍历-邻接表实现 (10 分)
本题要求实现邻接表存储图的深度优先遍历。函数接口定义:void DFS(ALGraph *G,int i);其中ALGraph是邻接表存储的图,定义如下:#define MAX_VERTEX_NUM 10 /*定义最大顶点数*/typedef int Vertex;typedef struct ArcNode{ /*表结点*/ int adjv...原创 2018-12-19 17:19:32 · 9414 阅读 · 0 评论 -
6-1 邻接矩阵存储图的深度优先遍历 (20 分)
试实现邻接矩阵存储图的深度优先遍历。函数接口定义:void DFS( MGraph Graph, Vertex V, void (*Visit)(Vertex) );其中MGraph是邻接矩阵存储的图,定义如下:typedef struct GNode *PtrToGNode;struct GNode{ int Nv; /* 顶点数 */ int Ne; ...原创 2018-12-19 17:20:16 · 4698 阅读 · 0 评论 -
7-2 Insert or Merge (25 分)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2018-12-14 19:03:00 · 561 阅读 · 0 评论 -
7-10 PAT排名汇总 (25 分)
计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科学的评价计算机程序设计人才,为企业选拔人才提供参考标准(网址http://www.patest.cn)。每次考试会在若干个不同的考点同时举行,每个考点用局域网,产生本考点的成绩。考试结束后,各个考点的成绩将即刻汇总成一张总的...原创 2018-12-15 20:10:33 · 1231 阅读 · 1 评论 -
7-12 抢红包 (25 分)
没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。输入格式:输入第一行给出一个正整数N(≤104),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:KN1P1⋯NKPK其中K(0≤K≤20)是发出去的红包个数,Ni是抢到红包的人的编号,P...原创 2018-12-15 20:50:26 · 698 阅读 · 0 评论 -
6-2 LCA in BST (25 分)
The lowest common ancestor (LCA) of two nodes u and v in a tree T is the deepest node that has both u and v as descendants. Given any two nodes in a binary search tree (BST), you are supposed to find ...原创 2018-12-10 14:39:07 · 412 阅读 · 1 评论 -
6-3 AVL Insertion (30 分)
You are supposed to implement the Insert function, which inserts an integer Key into an AVL tree T. The resulting tree must be returned.Format of function:AVLTree Insert ( AVLTree T, int Key );...原创 2018-12-10 14:51:03 · 2901 阅读 · 4 评论 -
7-2 字符串关键字的散列映射 (25 分)
7-2 字符串关键字的散列映射 (25 分)给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位;再用除留余数法将整数映射到长度为P的散列表中。例如将字符串AZDEG插入长度为1009的散列表中,我们首先将26个大写英文字母顺序映射到整数0~25;再通过移位将其映射为3×322+4×32+6=320...原创 2018-12-10 15:01:32 · 1728 阅读 · 0 评论 -
6-5 No Greater Than X in BST (20 分)
6-5 No Greater Than X in BST (20 分)You are supposed to output, in decreasing order, all the elements no greater than X in a binary search tree T.Format of function:void Print_NGT( Tree T, int ...原创 2018-12-10 15:02:57 · 997 阅读 · 0 评论 -
7-1 Maximum Subsequence Sum (25 分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequen...原创 2019-04-22 15:29:31 · 359 阅读 · 0 评论 -
6-2 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 adjacent sublists until one...原创 2018-12-13 23:10:27 · 2714 阅读 · 0 评论 -
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( int p, PriorityQueue H );...原创 2018-12-03 19:39:07 · 1513 阅读 · 0 评论 -
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 "false" elements precede "maybe" elemen...原创 2018-12-03 19:37:45 · 2084 阅读 · 0 评论 -
线性表的循环单链表存储结构
#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0typedef int ElemType;typedef int Status;typedef struct LNode{ ElemType data; struct LNode *next;}LNode,*Link...原创 2018-10-15 19:55:36 · 416 阅读 · 0 评论 -
线性表的双向链表存储结构
#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0typedef int ElemType;typedef int Status;typedef struct LNode{ ElemType data; struct LNode *next; struct L...原创 2018-10-15 19:58:51 · 2847 阅读 · 0 评论 -
线性表的循环双向链表存储结构
#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0typedef int ElemType;typedef int Status;typedef struct LNode{ ElemType data; struct LNode *next; struct L...原创 2018-10-15 19:59:26 · 167 阅读 · 0 评论 -
栈的顺序存储表示
#include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0#define OVERFLOW 0typedef int Status;typedef int SElemType;typ...原创 2018-10-15 20:00:28 · 182 阅读 · 0 评论 -
1到n的全排列(DFS)
#include <stdio.h>int a[10],book[100],n;void dfs(int step){ int i; if(step==n+1){ for(i=1;i<=n;i++) printf("%d",a[i]); printf("\n"); ...原创 2018-10-15 20:03:37 · 826 阅读 · 0 评论 -
遍历图(dfs)
#include <stdio.h>int book[101],sum,n,e[101][101];void dfs(int cur){ printf("%d ",cur); sum++; if(sum==n) return; for (int i=1; i<=n; i++) { if(e[cur][i]==...原创 2018-10-15 20:04:41 · 152 阅读 · 0 评论 -
二分查找
#include <stdio.h>#include <stdlib.h>#define MAXSIZE 10#define NotFound 0typedef int ElementType;typedef int Position;typedef struct LNode *List;struct LNode { ElementType Da...原创 2018-10-15 20:06:07 · 74 阅读 · 0 评论 -
冒泡法排序
#include <stdio.h>int main(int argc, const char * argv[]) { int N,K; scanf("%d %d",&N,&K); int a[N]; for (int i=0; i<N; i++) { scanf("%d",&a[i]); }...原创 2018-10-15 20:07:42 · 107 阅读 · 0 评论 -
习题1.9 有序数组的插入 (20 分)
bool Insert( List L, ElementType X ){ if(L->Last+1==MAXSIZE) return false; for (int i=0; i<=L->Last; i++) { if(L->Data[i]==X) return false; els...原创 2018-10-28 14:42:14 · 8572 阅读 · 0 评论 -
后缀表达式(堆栈的应用)
#include <stdio.h>#include <stdlib.h>#include <ctype.h>#define MAXOP 100#define INFINITY 1e9#define ERROR 1e9typedef double ElementType;typedef enum {num, opr, end} Type;ty...转载 2018-10-21 17:56:12 · 516 阅读 · 0 评论 -
7-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 gives...原创 2018-11-24 15:38:47 · 530 阅读 · 0 评论 -
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 from 1 to 6) is traversed, the stac...原创 2019-04-29 20:10:50 · 769 阅读 · 0 评论