
PTA_MOOC
lssssssssy
这个作者很懒,什么都没留下…
展开
-
06-图1 列出连通集
#include <stdio.h>#include <stdbool.h>#define N 10void ListComponentsWithDFS();void ListComponentsWithBFS();void DFS(int V);void BFS(int V);void InitVisit(void);int n;bool Visited[N];int G[N][N] = {0};int main(){ int E; .原创 2020-08-02 21:30:16 · 200 阅读 · 0 评论 -
05-树8 File Transfer
#include <stdio.h>#include <stdlib.h>#define MaxSize 10000typedef int ElementType; //默认元素可以用非负整数表示typedef int SetName; //默认根结点下标作为集合的名称typedef ElementType SetType[MaxSize]; //集合类型定义为数组/** 默认集合元素初始化 -1 1~N 计算机对应下标 0~N-1 元素下标为计算机的编号,对.原创 2020-07-10 18:47:59 · 177 阅读 · 0 评论 -
05-树7 堆中的路径
#include <stdio.h>#include <stdlib.h>#define MAXN 1001 //多一个哨兵#define MINH -10001int H[MAXN], size;void CreateHeap();void Insert(int X);int main(){ int N,M,X; int i,j; scanf("%d %d",&N,&M); CreateHeap(); .原创 2020-07-10 18:46:06 · 146 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集
BinTree Insert( BinTree BST, ElementType X ) { if( !BST ) { /* 若原树为空,生成并返回一个结点的二叉搜索树 */ BST = (BinTree)malloc(sizeof(struct TNode)); BST->Data = X; BST->Left = BST->Right = NULL; } else { /* 开始找要插入元素的位置 */ .原创 2020-07-09 09:18:10 · 129 阅读 · 0 评论 -
04-树5 Root of AVL Tree
#include <stdio.h>#include <stdlib.h>#define ElementType inttypedef struct AVLNode *Position;typedef Position AVLTree; /* AVL树类型,结构指针 */struct AVLNode { ElementType Data; /* 结点数据 */ AVLTree Left; /* 指向左子树 */ AVLTree Righ.原创 2020-07-09 09:16:42 · 118 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树
#include <stdio.h>#include <stdlib.h>typedef struct TreeNode *Tree;struct TreeNode { int V; Tree Left,Right; int flag; //设立被访问的标记,0未被访问,1被访问};Tree MakeTree(int N);Tree NewNode(int V);Tree Insert(Tree T, int V);int Judge(T.原创 2020-07-09 09:15:49 · 143 阅读 · 0 评论 -
03-树3 Tree Traversals Again
测试了30个元素的斜二叉树结果是对的,但是oj仍然有问题希望有大佬能够解答!#include <stdio.h>#include <stdlib.h>#include <string.h>#define MaxSize 30#define Null -1/**入栈顺序即先序遍历顺序,出栈顺序即中序遍历顺序已知先序遍历和中序遍历求后续遍历: 1 先+中 得到树的结构 2 后续遍历树注意,可以不用得出树的结构数组再得到后序遍历:.原创 2020-07-04 20:22:44 · 204 阅读 · 0 评论 -
03-树2 List Leaves
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define MaxSize 10#define Null -1#define Tree int//树struct TreeNode { int data; int left; int right;} T[MaxSize]; //树的结构数组,树的静态链表表示typedef struct TreeNode .原创 2020-07-04 20:18:09 · 136 阅读 · 0 评论 -
03-树1 树的同构
#include <stdio.h>#include <stdlib.h>#define MaxTree 10#define ElementType char#define Tree int#define Null -1 //c语言中NULL表示0,这里定义空指针Null表示-1struct TreeNode { ElementType Element; Tree Left; Tree Right;} T1[MaxTree], T2[Ma.原创 2020-07-04 20:17:03 · 167 阅读 · 0 评论 -
02-线性结构4 Pop Sequence
#include <stdio.h>#include <stdlib.h>/**手动判定: 对于出栈序列的某写元素,比某一元素早入栈却晚出栈,则该些元素逆序出栈 注意栈的空间有限程序判定: 根据待测序列,逆推最大空间为M的栈中元素 满足则YES 如果: 1 溢栈 2 未入栈(待测序列中)元素小于栈顶元素 则NO*/int main() { int M, N, K; sc.原创 2020-07-02 17:50:12 · 120 阅读 · 0 评论 -
02-线性结构3 Reversing Linked List
#include<stdio.h>#include<stdlib.h>typedef struct { int address; int data; int next;} Node;typedef Node *PtrNode;void ArrayList(Node L[], int N, int first);void ReverseList(Node L[], int N, int K);void exchange(PtrNode a,.原创 2020-07-02 17:49:01 · 124 阅读 · 0 评论 -
02-线性结构2 一元多项式的乘法与加法运算
#include <stdio.h>#include <stdlib.h>typedef struct PolyNode *Polynomial; //自定义类型名,多项式结构体指针PolynomialPolynomial ReadPoly();void Attach(int c, int e, Polynomial *pRear);Polynomial Add(Polynomial P1, Polynomial P2);Polynomial Mult(Polyn.原创 2020-07-02 17:47:45 · 308 阅读 · 0 评论 -
02-线性结构1 两个有序链表序列的合并
List Merge( List L1, List L2 ) { List L, rear,t1,t2; t1=L1->Next; t2=L2->Next; L=(PtrToNode)malloc(sizeof(struct Node)); L->Next=NULL; rear=L; while(t1&&t2) { if(t1->Data < t2->Data) { .原创 2020-07-02 17:46:21 · 176 阅读 · 0 评论 -
01-复杂度3 二分查找
Position BinarySearch( List L, ElementType X ){ int high = L->Last; int low = 1; while(low<=high){ int mid = (low+high)/2; if(L->Data[mid]==X){ return mid; }else if(L->Data[mid]>X){ .原创 2020-06-27 21:40:06 · 124 阅读 · 0 评论 -
01-复杂度2 Maximum Subsequence Sum
#include <stdio.h>#include <stdlib.h>int main() { int K = 0; scanf("%d", &K); int a[K]; for(int i=0; i<K; i++) scanf("%d",&a[i]); int MaxSum = -1; int ThisSum = 0; int low = 0; int newlow =.原创 2020-06-27 21:38:17 · 123 阅读 · 0 评论 -
01-复杂度1 最大子列和问题
#include <stdio.h>#include <stdlib.h>int main(){ int K = 0; scanf("%d", &K); int a[K]; for(int i=0; i<K; i++) scanf("%d",&a[i]); int MaxSum = 0; int ThisSum = 0; for(int i=0; i<K; i++){ .原创 2020-06-27 21:36:23 · 108 阅读 · 0 评论