C++自定排序規則

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;
}

面試需要準備的編程題

  1. 快排
  2. 堆排
  3. 歸併排
  4. TopK
  5. 深搜
  6. DP
  7. 並查集
  8. 最短路
  9. 雙指針
  10. 滑動窗口
  11. 前綴和 差分數組
  12. 二叉樹 最近公共祖先
  13. 離散化 二分法

基礎知識

異常:程序在運行期出現的錯誤。

常見的異常:

  1. 數組下標越界
  2. 除數爲零
  3. 內存不足

網絡編程

每個進程的進程空間都是私有的

管道是一種文件,半雙工,某一時刻只能單向傳輸,管道固定緩衝區大小爲4K

線程是調度的基本單位,進程是資源分配的基本單位。

線程切換可能會發生進程切換,也可能不發生,沒有必然聯繫。

線程獨有:棧,寄存器,線程ID,程序計數器。

進程調度策略:

  1. 先來先服務
  2. 短作業優先
  3. 優先級調度
  4. 高響應比調度
  5. 時間片輪轉
  6. 多級反饋隊列
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

  1. 互斥鎖
  2. 條件變量
  3. 讀寫鎖
  4. 信號量

docker

docker的優點

  1. 保證環境一致性
  2. 秒級的交付和部署
  3. 動態調度遷移成本低

計算機網絡七層模型

物數網傳會表應

物理層 數據鏈路層 網絡層 會話層 表示層 應用層

四層模型

數據鏈路層 網絡層 傳輸層 應用層

OSI七層模型和TCP/IP四層模型的區別:

網絡層上:七層模型面向連接和麪向無連接,四層模型面向無連接。

傳輸層上:七層模型面向無連接,四層模型面向有連接和無連接。

典型協議:TCP UDP HTTP FTP ARP RARP OSPF ICMP IGMP Telent

小端存儲:低存低,高存高。

待學的新技術

  1. Nginx
  2. redis
  3. docker
  4. netty
  5. zookeeper
  6. kafka
  7. rocketmq
  8. mangoDB
  9. hadoop
  10. Rabbitmq

redis

常用數據類型:string set zset hash list

常用數據結構:雙向鏈表 字典 跳錶 紅黑樹

vim快捷鍵

  1. Ctrl + n 光標下移
  2. Ctrl + P 光標上移
  3. Ctrl + b 光標左移
  4. Ctrl + f 光標右移
  5. Ctrl + a 行首
  6. Ctrl + e 行尾
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章