数据结构
yimfeng
What hurts more, the pain of hard work or the pain of regret?
展开
-
数据结构复习整理——线性表链式存储的基本操作
#include#include#include#includeusing namespace std;typedef int ElemType;struct LNode{ ElemType data; struct LNode *next;};//链表的建立struct LNode* Build(struct LNode *he原创 2017-11-30 18:17:27 · 443 阅读 · 0 评论 -
甲级pat-1009
#include<cstdio>const int maxn=5000;double arr[maxn]={0.0},arr1[maxn]={0.0},arr2[maxn]={0.0};int main(){ int n,m; scanf("%d",&n); int a; double b; for(int i=0;i<n;i...原创 2018-05-19 09:18:06 · 125 阅读 · 0 评论 -
甲级pat-1011
#include<cstdio>#include<algorithm>using namespace std;char s[3]={'W','T','L'};int main(){ double arr[3][3]={0},sum,fin[3],MAX=0.0; for(int i=0;i<3;i++) scanf("%lf %...原创 2018-05-19 09:20:06 · 126 阅读 · 0 评论 -
甲级pat-1002
#include<cstdio>#include<iostream>using namespace std;const int maxn=1001;int main(){ int n,m; scanf("%d",&n); int p; double c,arr[maxn]={0.0}; for(int i=0;i<...原创 2018-05-19 09:23:40 · 125 阅读 · 0 评论 -
甲级pat-1019
#include<cstdio>int main(){ int a,b,arr[1001]={0},len=0; scanf("%d %d",&a,&b); do{ arr[len++]=a%b; a=a/b; }while(a!=0); bool flag=true; for(int i...原创 2018-05-19 10:25:06 · 141 阅读 · 0 评论 -
甲级pat-1023
#include<iostream>#include<algorithm>using namespace std;int main(){ string s; cin>>s; int len=s.length(),arr_1[20],arr_2[20],arr_3[20],temp=0; for(int i=0;i<...原创 2018-05-19 10:49:48 · 162 阅读 · 0 评论 -
甲级pat-1025
能用vector尽量不用数组#include<cstdio>#include<algorithm>#include<vector>using namespace std;struct student{ long long int name; int mark; int type; int level1; int l...原创 2018-05-19 14:38:07 · 132 阅读 · 0 评论 -
甲级pat-1027
#include<cstdio>int main(){ char s[14]={"0123456789ABC"}; printf("#"); for(int i=0;i<3;i++){ int a; scanf("%d",&a); printf("%c%c",s[a/13],s[a%13]);原创 2018-05-19 14:41:57 · 157 阅读 · 0 评论 -
甲级pat-1030
#include<cstdio>#include<algorithm>using namespace std;const int maxn=1001;const int INF=10000000;int n,m,st,ed;int d[maxn],G[maxn][maxn],cost[maxn][maxn],w[maxn],pre[maxn];bool vis...原创 2018-05-21 19:28:50 · 193 阅读 · 0 评论 -
甲级pat-1032
#include<cstdio>#include<vector>using namespace std;const int maxn=100001;int hashTable[maxn]={0};struct Node{ int address; char data; int next;}node[maxn];int main(){ ...原创 2018-05-21 19:29:48 · 148 阅读 · 0 评论 -
甲级pat-1006
类型:sort函数排序#include<cstdio>#include<algorithm>#include<iostream>using namespace std;const int maxn=10010;struct Node{ string id; int in,out;}node[maxn];bool cmp1(Node ...原创 2018-05-19 09:12:24 · 143 阅读 · 0 评论 -
甲级pat-1005
#include<iostream>using namespace std;char arr[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};const int ma原创 2018-05-19 09:10:09 · 281 阅读 · 0 评论 -
甲级pat 1003
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1001;const int INF=10000000;int n,m,s,t;//d[]表示的是起始点到每个定点的最短路径,G[][]表示的是每两个定点之间的路径长度,cos...原创 2018-05-19 09:08:28 · 213 阅读 · 0 评论 -
数据结构复习整理——二叉树的基本操作
#include#include#includeusing namespace std;typedef char TElemType;typedef struct BiTNode{ TElemType data; struct BiTNode *lchild,*rchild;} BiTNode,*BiTree;//二叉树的建立void原创 2017-11-30 18:18:52 · 174 阅读 · 0 评论 -
数据结构复习整理——栈的基本操作
#include#include#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define ERROR 0#define OK 1typedef struct { int *base; int *top; int stacksize;}Sqstack;//建立栈in原创 2017-12-11 19:22:50 · 185 阅读 · 0 评论 -
数据结构复习整理——队列的基本操作
#include#include#define ERROR 0#define OK 1typedef struct QNode{ int data; struct QNode *next;}QNode,*QueuePtr;typedef struct { QueuePtr front; QueuePtr rear;}LinkQue原创 2017-12-11 19:23:48 · 249 阅读 · 0 评论 -
avl树的基本操作
#include<cstdio>#include<algorithm>#include<queue>using namespace std;struct node{ int v,height; //v为节点的权值,height为当前子树的高度 node *lchild,*rchild; //左右子树结点地址} *root;// 新建根节点node* ...原创 2018-05-10 20:42:48 · 366 阅读 · 0 评论 -
甲级pat-1115
#include<cstdio>#include<vector>#include<queue>using namespace std;struct Node{ int data; Node *lchild,*rchild;};// 进行二叉树的建立void insertData(Node* &root,int data){ if(roo...原创 2018-05-10 20:45:59 · 202 阅读 · 0 评论 -
堆排序
#include<cstdio>#include<algorithm>using namespace std;const int maxn=100010;int heap[maxn],n;void downAdjust(int low,int high){ int i=low,j=i*2; // i为欲调整的节点,j为其左子树 while(j<=high...原创 2018-05-10 20:47:30 · 95 阅读 · 0 评论 -
通过数组对二叉树进行遍历
在刷pat的时候经常遇到用数组进行存取二叉树,但是不会遍历二叉树(看来是我太菜了),原来数组存取的二叉树的遍历和普通的遍历基本相同,下面给出用数组存取二叉树的前序,中序和后序遍历。#include<cstdio>#include<vector>using namespace std;vector<int> v(1000,-1);int n;void preord...原创 2018-05-10 20:56:12 · 3943 阅读 · 1 评论 -
甲级pat-1107
#include<cstdio>#include<algorithm>using namespace std;const int maxn=1010;int father[maxn];int isRoot[maxn]={0};int course[maxn]={0};int findfather(int x){ int a=x; while(x...原创 2018-05-10 21:03:09 · 241 阅读 · 0 评论 -
甲级pat-1087
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<map>using namespace std;const int maxn=1000;const int INF=100...原创 2018-05-10 21:15:40 · 337 阅读 · 0 评论 -
甲级pat-1038
#include<iostream>#include<string>#include<algorithm>using namespace std;const int maxn=10001;string s[maxn];bool cmp(string a,string b){ return a+b<b+a; //使a<b}int...原创 2018-05-21 19:31:31 · 160 阅读 · 0 评论