STL——queue 常用函数

1. push()2. front()、back()3. pop()4. empty()5. size()
分类: 其他 发布时间: 03-06 09:49 阅读次数: 0

STL——stack 常用函数

1. push()2. top()3. pop()4. empty()5. size()stack 用来模拟实现一些递归,防止程序对栈内存的限制而导致程序运行出错。
分类: 其他 发布时间: 03-06 09:49 阅读次数: 0

algorithm 头文件下的常用函数

1. max()、min()、abs()2. swap()3. reverse(it, it2)4. next_permutation(a, a + 3)给出一个序列在全排列中的下一个序列。5. fill(a, a + 5, 233)6. sort(a, a + 3, cmp)7. lower_bound(first,last,val)用来寻找在数组或容器的 [ first, last ) 范围内第一个大于等于 val 的元素的位置。如果是数组,返回该位置的指针;如果是容器,返回该位置的迭代
分类: 其他 发布时间: 03-06 09:49 阅读次数: 0

图解后缀表达式的计算过程

为了解释后缀表达式的好处,我们先来看看,计算机如何应用后缀表达式计算出最终的结果20的。 后缀表达式:9 3 1-3*+ 10 2/+ 规则:从左到右遍历表达式的每个数字和符号,遇到是数字就进栈,遇到是符号,就将处于栈顶两个数字出栈,进行运算,运算结果进栈,一直到最终获得结果。 下面是详细的步骤: 1. 初始化一个空栈。此桟用来对要运算的数字进出使用。 2. 后缀表达式中前三个都是数字,所以9、3、1进栈...
分类: 其他 发布时间: 03-06 09:48 阅读次数: 0

将中缀表达式转换为后缀表达式

我们把平时所用的标准四则运算表达式,即“9+(3-1)*3+10/2"叫做中缀表达式。因为所有的运算符号都在两数字的中间,现在我们的问题就是中缀到后缀的转化。 中缀表达式“9+(3-1)*3+10/2”转化为后缀表达式“9 3 1-3*+ 10 2/+” 规则:从左到右遍历中缀表达式的每个数字和符号,若是数字就输出,即成为后缀表达式的一部分;若是符号,则判断其与栈顶符号的优先级,是右括号或优先级低于找顶符号(乘除优先加减)则...
分类: 其他 发布时间: 03-06 09:48 阅读次数: 0

栈与队列的应用——计算表达式的值

#include<iostream>#include<stdio.h>#include<string>#include<stack>#include<queue>#include<map>using namespace std;struct node{ double num; char op; bool flag;};string str;stack<node> s;queue<nod.
分类: 其他 发布时间: 03-06 09:48 阅读次数: 0

静态链表——sharing

#include<stdio.h>const int maxn = 100010;struct NODE{ char data; int next; bool flag;}node[maxn]; int main(){ for(int i = 0; i < maxn; i++) { node[i].flag = false; } int s1, s2, n; scanf("%d%d%d", &s1, &s2, &n); int a.
分类: 其他 发布时间: 03-06 09:48 阅读次数: 0

静态链表——sorting

#include<stdio.h>#include<algorithm>using namespace std;const int maxn = 100005;struct Node{ int address, data, next; bool flag;}node[maxn];bool cmp(Node a, Node b){ if(a.flag == false || b.flag == false) return a.flag > b.flag;.
分类: 其他 发布时间: 03-06 09:47 阅读次数: 0

DFS——背包问题

#include<stdio.h>const int maxn = 30;int n, V, maxValue = 0;int w[maxn], c[maxn];void DFS(int index, int sumW, int sumC){ // 死胡同 if(index == n) return; // 岔路口 —— 不选 DFS(index + 1, sumW, sumC); // 岔路口 —— 选 if(sumW + w[index] <= V).
分类: 其他 发布时间: 03-06 09:47 阅读次数: 0

DFS——选数问题

#include<stdio.h>#include<vector> using namespace std;const int maxn = 30;int n, k, x, maxSumSqu = -1, A[maxn];vector<int> temp;vector<int> ans;void DFS(int index, int nowK, int sum, int sumSqu){ if(nowK == k && s.
分类: 其他 发布时间: 03-06 09:47 阅读次数: 0

BFS——求矩阵中“块”的个数

#include<stdio.h>#include<queue>using namespace std;const int maxn = 100;struct node{ int x, y;}Node;int n, m; int matrix[maxn][maxn]; // 01矩阵 bool inq[maxn][maxn] = {false};int X[4] = {0, 0, 1, -1};int Y[4] = {1, -1.
分类: 其他 发布时间: 03-06 09:47 阅读次数: 0

BFS——走迷宫的最小步数

#include<stdio.h>#include<string.h>#include<queue>using namespace std;const int maxn = 100;struct node{ int x, y; int step;}S, T, Node;int n, m; char maze[maxn][maxn]; // 迷宫信息 bool inq[maxn][maxn] = {false};i..
分类: 其他 发布时间: 03-06 09:46 阅读次数: 0

二叉树的遍历——DFS

先序遍历void preorder(node* root){ if(root == NULL) return; printf("%d\n", root->data); preorder(root->lchild); preorder(root->rchild);}中序遍历void inorder(node* root){ if(root == NULL) return; inorder(root->lchild); printf("%d\n", root.
分类: 其他 发布时间: 03-06 09:46 阅读次数: 0

二叉树的遍历——BFS

void LayerOrder(node* root){ queue<node*> Q; root->layer = 1; Q.push(root); while(!Q.empty()) { node* now = Q.front(); Q.pop(); printf("%d ", now->data); if(now->lchild != NULL) { now->lchild->layer = now->layer .
分类: 其他 发布时间: 03-06 09:46 阅读次数: 0

二叉树的遍历——还原二叉树

#include<stdio.h>#include<queue>using namespace std;const int maxn = 50;struct node{ int data; node* lchild; node* rchild;};int post[maxn], in[maxn];int n;node* create(int postL, int postR, int inL, int inR){ if(postL > postR.
分类: 其他 发布时间: 03-06 09:46 阅读次数: 0

树的DFS——Path of Equal Weight

#include<stdio.h>#include<vector>#include<algorithm>using namespace std;const int MAXN = 110;struct node{ int weight; vector<int> child;}Node[MAXN]; // 静态树bool cmp(int a, int b){ return Node[a].weight > Node[b]...
分类: 其他 发布时间: 03-06 09:45 阅读次数: 0

BST 的基本操作

插入及建立void insert(node* &root, int x){ if(root == NULL) { root = newNode(x); return; } if(x == root->data) return; else if(x < root->data) insert(root->lchild, x); else insert(root->rchild, x);}node* Create(int data[], in
分类: 其他 发布时间: 03-06 09:45 阅读次数: 0

BST—— Is it a Binary Search Tree

#include<stdio.h>#include<vector>using namespace std;struct node{ int data; node *left, *right;};void insert(node* &root, int data){ if(root == NULL) { root = new node; root->data = data; root->left = NULL; root-&g.
分类: 其他 发布时间: 03-06 09:45 阅读次数: 0

AVL 的基本操作

LL 与 LRRR 与 RL插入及建立#include<stdio.h>#include<vector>#include<algorithm>using namespace std;struct node{ int v, height; node *lchild, *rchild;};node* newNode(int v){ node* Node = new node; Node->v = v; Node->he
分类: 其他 发布时间: 03-06 09:44 阅读次数: 0

并查集——好朋友

#include<stdio.h>const int maxn = 110;int father[maxn];bool isRoot[maxn];void init(int n){ for(int i = 1; i <= n; i++) { father[i] = i; isRoot[i] = false; }}int findFather(int x){ while(x != father[x]) { x = father[x]; } retu.
分类: 其他 发布时间: 03-06 09:44 阅读次数: 0