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 行尾