上机考试常用数据结构及函数

上机考试常用数据结构及算法
1.栈stack(先进后出)

#include<Stack>//头函数
Stack<type> s;
s.size();
s.top();
s.pop();
s.push();
s.empty();//return a bool value;

2.队列queue(先进先出)

#include<queue>
queue<type> q;
q.size();
q.front();// return the primary element of queue
q.pop();
q.push(x);
q.empty();

3.pair<>

pari<type1,type2>Q;//头函数另说;
make_pair(type1 value1,type2 value2);
Q.first;
Q.second;

4.vector

#include<vector>
vector<type> V;
V.size();
V.push_back();
V.pop_back();
V.begin();//return a iterator pointing to begin of the vector
V.end();// return next iterator of the last element
V.insert(p,x)//insert x in the location of p;
V.erase(p);//delete the element of the location p;
V.clear();//clear all elements;


5.list

#include<list>
list<type>l;
l.size();
l.begin();
l.push_front();// add an element to the begin of list
l.push_back();--------------------------last
l.pop_front();
l.pop_back();
l.insert(p,x);
l.erase(p);
l.clear();
for(list<type>::iterator it=l.begin();it!=l.end();it++//forum

6.Search

#include<algorithm>
binary_search();
lower_bound(a,a+n,x)//return the first iterator that pointing the element no less than x;
//the type of a is vary;
uper_bound();//using such as l_b;


7.递归与分治

#include<iostream>
//typical example of recursion:factorial
int factorial(int n){
if(n==1) return 1;
 return n*factorial(n-1);
}
//find maximum achieve by Divide-and-Conquer
int findMaximum(type A,begin l, end r){
   m=(l+r)/2;
   if(l==r-1)
       return A[l];
   else{
   u=findMaximum(A,l,m)//divide
   v=findMaximum(A,m,r)
   x=max(u,v)//conquer
   }
   return x;
}

8.二叉搜索树

#include<set>//set is sorted by value of element ,no element errepeation and ascending order
#include<map>
set<type>s;
s.size();
s.clear();
s.begin();
s.end();
s.insert(key);
s.earse(key);
s.find(key);
map<keyType key,vlaueType value>m;//no repeated key ,and key is the standard of sortion
//type is vary
m.size();
m.clear();
m.begin();
m.end();
m.insert((key,value));//pair can be used here
m.erase(key);
m.find(key);

9.priority_queue

#include<queue>
priority_queue<int>PQ;//the top element have the highest priority,default to ascending order
//usage is same as queue

10BFS and DFS

在这里插入代码片

暂时先写到这

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值