set自定义排序
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
// set存放自定义数据类型
class Student{
public:
Student(string name, int age){
this->name = name;
this->age = age;
}
string name;
int age;
};
class comparePerson{
public:
bool operator()(const Student &a, const Student b){
return a.age > b.age;
}
};
int main(){
set<Student, comparePerson> st;
st.insert({"zhang", 18});
st.insert({"wang", 19});
st.insert({"zhao", 10});
st.insert({"li", 5});
for(auto it: st){
cout<<it.name<<" "<<it.age<<endl;
}
return 0;
}
priority_queue自定义排序
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
// set存放自定义数据类型
class Student{
public:
Student(string name, int age){
this->name = name;
this->age = age;
}
string name;
int age;
};
class comparePerson{
public:
bool operator()(const Student &a, const Student b){
if(a.age != b.age) return a.age < b.age;
return a.name > b.name;
}
};
int main(){
priority_queue<Student, vector<Student>, comparePerson> pq;
pq.push({"zhang",19});
pq.push({"wang",9});
pq.push({"wu",12});
pq.push({"zhaa",13});
pq.push({"zhao",13});
while(pq.size()){
cout<<pq.top().name<<" "<<pq.top().age<<endl;
pq.pop();
}
return 0;
}
map使用pair插入
ios::sync_with_stdio(false);
map<int,int> mp;
mp.insert(make_pair(1,1));
mp[1] = 12;
随机数算法
#include<iostream>
#include <random>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<int> vt{1,4,3,6};
mt19937 rnd(time(0)); //产生一个大的随机数
shuffle(vt.begin(), vt.end(), rnd);
for(int it: vt){
cout<<it<<endl;
}
return 0;
}
面试需要准备的编程题
- 快排
- 堆排
- 归并排
- TopK
- 深搜
- DP
- 并查集
- 最短路
- 双指针
- 滑动窗口
- 前缀和 差分数组
- 二叉树 最近公共祖先
- 离散化 二分法
基础知识
异常:程序在运行期出现的错误。
常见的异常:
- 数组下标越界
- 除数为零
- 内存不足
网络编程
每个进程的进程空间都是私有的
管道是一种文件,半双工,某一时刻只能单向传输,管道固定缓冲区大小为4K
线程是调度的基本单位,进程是资源分配的基本单位。
线程切换可能会发生进程切换,也可能不发生,没有必然联系。
线程独有:栈,寄存器,线程ID,程序计数器。
进程调度策略:
- 先来先服务
- 短作业优先
- 优先级调度
- 高响应比调度
- 时间片轮转
- 多级反馈队列
stat test.txt. //查看文件信息
fcntl //对打开的文件设置阻塞与非阻塞
df //查看磁盘空间
du //查看文件和目录占用空间
dup2 dup //文件描述符拷贝
fork //创建子进程
exec //在程序中运行其他程序
whoami //查看用户
chmod //修改用户的权限
wait waitpid //等待回收子进程
TCP客户端:socket connect write read close
TCP服务端: socket bind listen accept read write close
fgets(s, n, stdin) //从终端读入字符串
线程同步:mutex
- 互斥锁
- 条件变量
- 读写锁
- 信号量
docker
docker的优点
- 保证环境一致性
- 秒级的交付和部署
- 动态调度迁移成本低
计算机网络七层模型
物数网传会表应
物理层 数据链路层 网络层 会话层 表示层 应用层
四层模型
数据链路层 网络层 传输层 应用层
OSI七层模型和TCP/IP四层模型的区别:
网络层上:七层模型面向连接和面向无连接,四层模型面向无连接。
传输层上:七层模型面向无连接,四层模型面向有连接和无连接。
典型协议:TCP UDP HTTP FTP ARP RARP OSPF ICMP IGMP Telent
小端存储:低存低,高存高。
待学的新技术
- Nginx
- redis
- docker
- netty
- zookeeper
- kafka
- rocketmq
- mangoDB
- hadoop
- Rabbitmq
redis
常用数据类型:string set zset hash list
常用数据结构:双向链表 字典 跳表 红黑树
vim快捷键
- Ctrl + n 光标下移
- Ctrl + P 光标上移
- Ctrl + b 光标左移
- Ctrl + f 光标右移
- Ctrl + a 行首
- Ctrl + e 行尾