《葵花宝典》计算机网络篇幅 七层网络模型和五层网络模型, 以及各自都有哪些常见协议?物理层链路层网络层:ARP, IP, ICMP传输层:TCP UDP会话层 |表示层 | --- HTTP SMTP POP SSL FTP应用层 |TCP、UDP对比,使用选择a. TCP是面向连接的可靠数据传输服务,UDP则提供无连接的不可靠数据传输服务b. TCP只支持点到点的数据传输服务, UDP支持一对一、一对多、多对一、多对多交互通信c. TCP有拥塞控制、流量控制; UDP没有拥塞控制d. TC
20220323华为笔试 1#include <vector>#include <queue>#include <iostream>using namespace std;int help(vector<int>& num){ vector<bool> is_used(num.size(), false); queue<int> q; q.push(0); is_used[0] = true; int
acwing笔记 文章目录基础知识快速排序归并排序二分查找基础数据结构数组模拟单链表trie字符串统计并查集堆模板搜索和图论邻接表数组实现dfsbfskmp最短路最小生成树二分图数学知识动态规划dp背包问题贪心基础知识快速排序/** * @brief: 快速排序: 递归,分治 * @time cpl: O(nlog n) * @space cpl: O(1) * @trouble: **/template <typename type>void quick_sort_helper(type
c++手写堆 #include <iostream>#include <vector>template<typename type, typename cmp>class ToyHeap{public: ToyHeap(std::vector<type>& vec):num(vec){ init(); } void init(){ for(int i=num.size()/2; i>=0;
20220303蔚来笔试 1#include <iostream>#include <algorithm>#include <cstring>#include <string>using namespace std;const int N = 110;int num[N];int v;int main(){ int t; int idx = 0; int mx = -1; while(cin >> t){
20220305网易笔试 1#include <vector>const int N = 200010;int p[N];int find(int x){ if (p[x] != x) p[x] = find(p[x]); return p[x];}class Solution {public: bool validPath(int n, vector<vector<int> >& sides, int start, int end) {
20220305美团笔试 1#include <iostream>#include <set>#include <vector>#include <algorithm>using namespace std;const int N = 200010;bool num[N];int main(){ int n; scanf("%d", &n); for(int i=0; i<n; i++){ int t; scanf(
20220307shopee笔试 1乘积最大子数组详细描述给你一个整数数组 nums ,请在时间复杂度为O(n) 下找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积其他时间限制: 1000ms内存限制:256.0MB输入输出示例示例1输入复制[2,3,-2,4,-1]输出复制48class Solution {public: /** * Note: 类名、方法名、参数名已经指定,请勿修改 * * * 找到数组
20220312完美世界笔试 1// 可以引入的库和版本相关请参考 “环境说明”#include <iostream>#include <unordered_map>#include <string>using namespace std;string solution(string str) { string res = ""; if(str.empty()) return res; unordered_map<string, int> fmp;
CPP服务器08--http请求响应实现 http服务设计对于静态页面服务器来说,其工作流程如下:- 接收客户端消息- 解析出http请求报文- 业务逻辑,拼装响应报文- 发送给客户端结果http连接类设计目标:将客户端唯一文件描述符封装,表示成一个连接实体.从socket读报文–>buffer存储给socket写报文–>buffer存储解析逻辑-->进一步划分給子类去做 requests类响应逻辑-->进一步划分給子类去做 response类头文件#ifndef HTTP_CONN_H#
CPP服务器07--服务器层次分析及其设计 IO复用EPOLL服务器设计软件层次设计 WebServer :服务器逻辑框架: epoller监听+线程池读写 | | Epoller Timer :epoll操作封装, 定时器给连接计时 | | ---------- |
CPP服务器06--线程池实现(2) 线程池封装说明:上篇文章中的线程池,功能相对完整,有管理调度线程.但接口定义通用性差,需要修改,奈何目前水平不够,只能先找一个能用的替换,以后再改吧.阅读建议:// std::thread :https://subingwen.cn/cpp/thread/// std::function :https://blog.csdn.net/jinzhu1911/article/details/101307637// template<typename F,typename…
CPP服务器05--线程池实现(1) 线程池封装 1实现思路:组件:pthread_t *workers; //工作线程数组pthread_t manager; //管理者线程TaskQueue *task_queue; //任务队列思路:多个工作线程,外部线程添加任务,结合阻塞任务队列实现生产消费者模型;管理者线程负责工作线程的调度策略比如说,存活数小于设定最大线程数且存在未执行任务,则创建线程当忙碌线程小于当前存活线程数且,则进行线程销毁.实现: 任务和任务队列#i
CPP服务器04--Epoll反应器封装 Epoller反应器封装实现思路:容器:std::vector events_;操作:对epoll创建,关闭,添加,修改,删除,等待进行封装头文件#ifndef EPOLLER_H#define EPOLLER_H#include <sys/epoll.h> //epoll_ctl()#include <fcntl.h> // fcntl()#include <unistd.h> // close()#include <assert.h&
CPP服务器03--日志类实现 日志类实现功能需求:- 允许多个线程同时写,但刷入磁盘必须保持相对顺序实现思路:组件:阻塞队列 std::unique_ptr<BlockQueuestd::string> queue_;刷盘线程 std::unique_ptrstd::thread writeThread_;日志容器 Buffer buff_;互斥锁 std::mutex mtx_;思路:单例模式实现一个日志类;外界调用不断添加日志进阻塞队列queue_;写线程不断从阻塞队列取日志刷盘
CPP服务器02--字符读写缓冲区封装 字符读写缓冲区封装功能需求:对一个文件描述符进行读写操作,需要可自动调整大小的缓冲区实现思路:容器:std::vector buff操作:维护读写两个指针记录当前读写位置,扩容:若写指针达到当前buff尾,且数据未读完缩减:每次操作完成,重置缓冲区头文件#ifndef BUFFER_H#define BUFFER_H#include <cstring> //perror#include <iostream>#include <unis
CPP服务器01--阻塞队列的实现 阻塞队列1. 实现原理:1. 容器:std::queue<T> 2. 逻辑:使用一把互斥锁控制队列这个临界资源的访问; 使用条件变量控制入队出队操作(队满则入队阻塞,队空则出队阻塞);#include "../log/blockqueue.hpp"#include "pthread.h"#include <cstdlib>#include <ctime>#include <unistd.h>std::unique_ptr<Bloc
腾讯音乐笔试 一、 树自上往下每层循环右移k位#include <vector>#include <iostream>#include <deque>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(nullptr), right(nullpt