![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构笔记
_ymi
/(ㄒoㄒ)/~~
展开
-
栈 表达式求值
把运算的处理专门放在一个函数里,然后通过优先级的判断去调用函数,注意那个’('还是放在else if里面吧,不要和运算混在一起了#include<bits/stdc++.h>using namespace std;const int N=1e5+10;stack<int> s1;stack<char> s2;int flag=0;//处理+-*/四个 map<char,int> cmp={ {'+',1}, {'-',1} , {'*',原创 2021-03-17 11:21:13 · 73 阅读 · 0 评论 -
排序
O(n^2)选择排序冒泡排序插入排序#include<iostream>#include<cstring>using namespace std;void swap(int &a,int &b){ int t=a; a=b; b=t;}void bubble_sort(int *array,int size){ int flag=1; for(int i=1;flag && i<size;i++){ flag=原创 2020-12-24 20:41:57 · 99 阅读 · 2 评论 -
堆 46
h->data =new int[max+1];这里是中括号才行!#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<climits>using namespace std;typedef struct Node{ int *data; int size; int capacity;}heap,*Heap;.原创 2020-12-24 17:52:35 · 162 阅读 · 2 评论 -
图的一系列操作c++
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<vector> #include<map>#include<queue>using namespace std;//基类class Graph{protected: int n_v;//顶点数量 bool directed;//有向的 ve原创 2020-12-22 11:04:46 · 105 阅读 · 2 评论 -
Tree Traversal again
题目链接根据前序和中序写出后序—可以创建出树再后序遍历—也可以不创建出树直接把后序遍历的结构存到数组两种代码差不多,之前写的并没有理解,重新写一遍要注意一些细节,以及递归出口有两个。#include<stack>#include<iostream>#include<cstring>using namespace std;int pre[50],in[50],post[50];int flag=0;void sol(int pre_f,int in_原创 2020-12-20 22:03:49 · 134 阅读 · 1 评论 -
DisJoint_Set
//不相交集的概念(并查集) Union Find //disjoint set && set//查找某个元素在那个集合 //map <A B > key - value#include<iostream>#include<set>#include<map>using namespace std;typedef struct Disjoint_Set{ int *data; int *parent;//负数利用起来原创 2020-12-08 11:52:56 · 151 阅读 · 0 评论 -
最近遇到的错误
最近一直犯一些很憨的错误(lll¬ω¬)1最小堆,就是基本的插入/删除操作,然后插入的时候调用up上溯函数,删除的时候调用down下溯函数①这里的改成x,或者不改无所谓②如果Traverse里面有递归哈,那个flag判断空格的就要放在函数外面,i也要放在外面另一种打印方法没用flag,我觉得也很好哈哈void printheap(Heap h){ for(int i = 1; i < h->size; i++) cout << h->data[i] <原创 2020-11-25 22:11:09 · 114 阅读 · 0 评论 -
根据xz hz创建树
1.xzBinT creat_Tree(char *a,char *b,int n){ BinT T; int i=0; if(!n) return NULL; T=new Tree(); T->data =a[0]; for(i=0;i<n;i++){ if(a[0]==b[i]) break; } //创建树就是把他们连起来,左右 T->left =creat_Tree(a+1,b,i); T->right =creat_Tree(a+1+i,b+原创 2020-11-10 22:10:31 · 281 阅读 · 0 评论 -
二叉树的顺序操作
注意的地方1 结构体数组2 floor函数 向下取整--------ceil函数 向上取整---------round函数 四舍五入取整当然要头文件#include<math.h>3 函数中把要改变的结果引用传过去,,,#include<bits/stdc++.h>using namespace std;int n;int flag=0;typedef struct Tree{ int data; bool isEmpty;}Tree;void Ini原创 2020-11-10 20:42:10 · 116 阅读 · 0 评论 -
二叉树的创建&&遍历
#include<iostream>#include<cstring>#include<cmath>#include<algorithm> #include<queue>using namespace std;typedef struct Tree{ int data; struct Tree* left; struct Tree* right;}Tree,*Bin;int flag=1;Bin pre_Create(){原创 2020-11-10 20:18:04 · 63 阅读 · 0 评论 -
中缀转后缀输出-普通版
1 如果有结束符的时候,用char//判断的时候有结束符 //就单个字符 char判断 #include<bits/stdc++.h>#include<ctype.h>using namespace std;#define Maxsize 100typedef struct Stack{ int data[Maxsize];//0~Maxsize-1 int top;}Stack,*pStack; pStack CreateStack(){ pStack原创 2020-10-24 21:18:05 · 75 阅读 · 0 评论 -
一元多项式
两种空间复杂度不一样#include<bits/stdc++.h>using namespace std;typedef struct node{ int coef; int expon;//指数 struct node* next;}node,*pnode;pnode CreateNode(){ pnode head,end,p; head=new node(); head->next =NULL; end=head; int n;cin>>n;原创 2020-10-13 21:48:08 · 168 阅读 · 0 评论 -
单向链表的逆转
pNode Reverse(pNode L){ pNode temp,p=NULL;// temp=L->next ;//原链表无头结点 temp=L->next->next ; L=L->next ; pNode q; q=new Node(); q->next =NULL; while(temp){ L->next =p; p=L; L=temp; temp=L->next; } L->next =p; p原创 2020-09-29 19:05:51 · 145 阅读 · 0 评论 -
链表
1.创建一个带有头结点的单链表 head=new Node(); head->next =NULL;尾插法: end=head; int n;cin>>n; while(n--){ p=new Node(); cin>>p->data; end->next=p; end=p; } end->next =NULL;//必须要有头插法:int n;cin>>n; while(n--){ p=new Node原创 2020-09-28 18:35:01 · 71 阅读 · 0 评论