- 博客(19)
- 问答 (1)
- 收藏
- 关注
原创 堆排序
#include<cstdio>#include<algorithm>using namespace std;void PercDown( int A[], int p, int N ){ /* 将N个元素的数组中以A[p]为根的子堆调整为最大堆 */ int Parent, Child; int X; X = A[p]; /* 取出根结点存放的值 */ for( Parent=p; (Parent*2+1)<N; Paren
2020-05-27 17:01:19 89
原创 7-4 是否同一棵二叉搜索树
方法还是固定的建树 然后用vector存放遍历的结果 利用vector可以直接判断是否相等的好处 判断遍历结果是否一样。#include<vector>#include<cstdio>#include<stdlib.h>using namespace std;typedef struct node{ struct node* left; struct node*right; int data;}*bintree;vector<int>b..
2020-05-26 20:57:27 110
原创 08-图8 How Long Does It Take
#include<cstdio>#include<algorithm>#include<queue>using namespace std;const int maxn = 550;const int INF = 1000000000;int n,m;int G[maxn][maxn];int earlist[maxn] = {0};int indegree[maxn] = {0};void tporder(){ int num = 0; q...
2020-05-23 21:40:24 118
原创 04-树5 Root of AVL Tree
#include<cstdio>#include<algorithm>#include<stdlib.h>using namespace std;struct node{ struct node*left; struct node*right; int height; int data;};typedef struct node*AVLTree;int getheight(AVLTree T){ if(T==NULL) return 0;...
2020-05-23 21:37:26 71
原创 05-树7 堆中的路径
#include<cstdio>#include<stdlib.h>struct node{ int *data; int size;};typedef struct node *minheap;minheap create(int maxsize){ minheap h = (minheap)malloc(sizeof(struct node)); h->data = (int*)malloc(sizeof(int)*(maxsize+1)); h-..
2020-05-23 21:33:46 84
原创 pat 1076
测了好几个数据 都是正确的 怎么PAT一个测试点都通过不了 先放着#include<cstdio>#include<vector>#include<queue>#include<algorithm>using namespace std;int n,level;vector<int>G[1100];bool vis[1100] ={false};int BFS(int root,int k){ int count; int l
2020-05-20 21:57:05 144
原创 PAT 1053
很奇怪 给权值排序 weight开的够大 最后一个测试点就能通过而给vector<vector>排序就通不过最后一个测试点#include<cstdio>#include<vector>#include<algorithm>#include<iostream>using namespace std;struct node{ int data; vector<int>child; int father;}Node[1
2020-05-19 23:38:07 112 1
原创 一般的树
子结点个数没有限制并且没有先后次序struct node{ int data; vector<int>child;}Node[maxn];先根遍历void preorder(int root){ printf("%d",Node[root].data); for(int i=0;i<child.size();i++){ preorder(Node[root].child[i]); }}层序遍历 void levelorder(int root){ que
2020-05-19 22:50:50 91
原创 PAT (Advanced Level) Practice 1104 Sum of Number Segments (20分)
#include<cstdio>int main(){ int n; scanf("%d",&n); double sum = 0; double x; int k = 0; for(int i=1;i<=n;i++){ scanf("%lf",&x); sum += x*i*(n-k); k++; } printf("%.2f",sum); return 0;}****① i * n;② i * n- i;③ i * n-2
2020-05-14 22:31:37 81
原创 PAT (Advanced Level) Practice 1123 Is It a Complete AVL Tree (30分)
#include<cstdio>#include<algorithm>#include<stdlib.h>#include<queue>const int maxn = 2020;using namespace std;struct node{ struct node*left; struct node*right; int height; int data;};typedef struct node*AVLTree;int n;i
2020-05-13 18:04:03 83
原创 树
二叉树的遍历前序遍历(动态写法、静态写法)//中序 后序同理void preorder(bintree bt){ printf("%d",bt->data); preorder(bt->left); preorder(bt->right);} void preorder(int root){ printf("%d",tree[root].data); preorder(tree[root].left); preorder(tree[root].right);}
2020-05-12 20:04:14 118
原创 03-树1 树的同构
#include<cstdio>using namespace std;struct node{ int left; int right; int root; char id;}tree[20],bt[20];int main(){ int n; char l,r; char c; scanf("%d",&n); for(int i=0;i<n;i++){ tree[i].left = -1; tree[i].right = -1; tree
2020-05-12 09:54:09 60
原创 PAT (Advanced Level) Practice 1001 A+B Format
第一次以为输出的隔三位是这种形式100,0结果卡了好久…sprintf可以把n以%d的格式写到str字符数组中sprintf(str,"%d",n)#include<cstdio>int main(){ int a,b; int len[10]; int count = 0; scanf("%d%d",&a,&b); int sum = a+b; if(sum<0){ printf("-"); sum = -sum; } if(sum=..
2020-05-11 23:59:04 52
原创 03-树1 树的同构
#include<cstdio>using namespace std;struct node{ int left; int right; int root; char id;}tree[20],bt[20];int main(){ int n; char l,r; char c; scanf("%d",&n); for(int i=0;i<n;i++){ tree[i].left = -1; tree[i].right = -1; tree
2020-05-11 15:36:32 58
原创 二叉搜索树插入操作
bintree insert(int x,bintree bst){ if(!bst){ bst = (bintree)malloc(sizeof(struct node)); bst->data = x; bst->left=bst->right = NULL; }else{ if(bst->data>x) bst->left=insert(int x,bst->left); else if(bst->data<x) bst-&
2020-05-10 20:41:24 154
原创 PAT (Advanced Level) Practice 1102 Invert a Binary Tree
#include<cstdio>#include<queue>#include<stack>using namespace std;struct node{ int lchild; int rchild; int root;}tree[20];void inorder(int root);void leaveorder(int root);int in[20];int index= 0;int n;int main(){ scanf("%d
2020-05-10 14:54:07 106
原创 PAT (Advanced Level) Practice 1020 Tree Traversals
给出后序遍历和中序遍历的结果 可以得到前序遍历和层序遍历。beetree create(int postl,int postr,int inl,int inr){ if(postl>postr) return NULL; beetree root = (beetree)malloc(sizeof(struct node)); root->data = post[postr]; int k; for(k=inl;k<inr;k++){ if(in[k]==post[p..
2020-05-10 11:38:12 111
原创 03-树2 List Leaves
本题要求的是叶结点 就是度为0的结点 并且要按照上下 左右的顺序输出。一首先要找到根节点 求根节点的方法就是找到那个没有其他结点的左右子结点能够指到的位置 那个位置就是根节点。树的顺序存储结构的具体方法是多加一个root的变量struct node{ int left; int right; int root;}tree[maxsize]; 首先给所有的root赋值令其为-1;然后在输入数据的时候令tree[子节点.left] = 0 tree[子节点.right] = 0;所..
2020-05-09 22:08:08 94
原创 mooc 数据结构第2章:读入多项式里面为什么要传指针进去
#include<stdio.h>#include<stdlib.h>struct node{ int data; struct node*next;};typedef struct node *list;void attack(list *l,int x);int main(){ list a = (list)malloc(sizeof(struct node)); a->data = 5; printf("%d\n",a->data); at
2020-05-08 23:20:18 85
空空如也
vs2019安装显示文件存在?
2020-05-07
TA创建的收藏夹 TA关注的收藏夹
TA关注的人