- 博客(109)
- 资源 (3)
- 收藏
- 关注
原创 01.gdb调试
环境准备 linux操作系统:物理机,云服务器,虚拟机 c++开发调试环境准备 安装gcc,g++,gdb 在ubuntu平台: apt install gcc g++ make gdb 在centos平台: yum install gcc gcc-c++ make gdb linux下的调试工具gdb https://www.sourceware.org/gdb/ makefile参数: CFLAGS: -g 有了-g参数调试比较方便,如果没有-g参数,就没有调试信息,调试比较的困难 gd
2022-05-14 00:25:10
277
原创 02.mysql的CURD1
结构化查询语句SQL SQL是结构化查询语言(Structure Query Language),它是关系型数据库的通用语言。 SQL主要可以划分为以下 3 个类别: DDL(Data Definition Languages)语句 数据定义语言,这些语句定义了不同的数据库、表、列、索引等数据库对象的定义。常用的语句关键字主要包括 create、drop、alter等。 DML(Data Manipulation Language)语句 数据操纵语句,用于添加、删除、更新和查询数据库记录,并检查数据完整
2022-05-13 20:46:33
428
原创 01.socket初步
1、什么是Socket 在计算机通信领域,socket 被翻译为“套接字”,它是计算机之间进行通信的一种约定或一种方式。通过 socket 这种约定,一台计算机可以接收其他计算机的数据,也可以向其他计算机发送数据 socket起源于Unix,而Unix/Linux基本哲学之一就是“一切皆文件”,都可以用“打开open –> 读写write/read –> 关闭close”模式来操作。 2.socket一些参数 SOCK_STREAM:表示面向连接的数据传输方式。 SOCK_DGRAM:表示
2022-05-12 23:11:05
1080
原创 01.mysql基础知识概述
mysql配置文件 /var/lib/mysql/ 数据文件 /etc/my.cnf 配置文件 mysql数据类型 数值类型 字符串类型 日期和时间类型 注意: TIMESTAMP会自动更新时间,适合那些需要记录最新更新时间的场景,DATETIME需要手动更新。 mysql运算符 算数运算符 逻辑运算符 比较运算符 mysql常用的函数 时间和日期函数 NOW():返回当前的日期和时间 UNIX_TIMESTAMP(data):返回日期date的UNIX时间戳 CURRENT_TIMESTAM
2022-05-12 22:52:52
277
原创 002.进程api
1.fork()系统调用 系统调用 fork()用于创建新进程. #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]) { printf("hello world (pid:%d)\n", (int) getpid()); int rc = fork(); if (rc < 0) { // fork faile
2022-05-12 00:08:17
310
原创 001.操作系统初步浅谈
操作系统运行程序过程 必须做的第一件事是将代码和所有静态数据(例如初始化变量)加载(load)到内存中,加载到进程的地址空间中。 程序最初以某种可执行格式驻留在磁盘上,因此,将程序和静态数据加载到内存中的过程,需要操作系统从磁盘读取这些字节,并将它们放在内存中。 将代码和静态数据加载到内存后,操作系统在运行此进程之前还需要执行其他一些操 作。必须为程序的运行时栈(run-time stack 或 stack)分配一些内存。 进程的状态 运行(running):在运行状态下,进程正在处理器上运行。这意
2022-05-11 23:24:21
492
原创 10.BF和KMP算法
BF算法 时间复杂度:O(n*m) n表示主串的长度,m表示子串的长度 空间复杂度:O(1) 匹配串 A(“abcac”)是否为串 B(“ababcabacabab”)子串: 第一次: 第二次: 第三次: 直到第六次匹配成功: 代码 #include<iostream> using namespace std; //返回子串在主串中的索引 int BF(string s, string t) { int i = 0; int j = 0; while (i < s.
2022-05-10 22:45:59
202
原创 002.算法
知识总览 程序 算法的特性 有穷性 确定性 可行性 输入,输出 好算法的特质 正确性 可读性 健壮性 高效率和低存储 算法的时间复杂度 算法的时间复杂度 算法空间复杂度
2022-04-24 09:09:12
369
原创 001.绪论
本章总览 1.数据结构基本概念 数据 数据元素 数据项 数据对象 数据结构 2.数据结构数据结构三要素 数据结构关注数据元素之间的关系 逻辑结构 物理结构(存储结构) 线性结构 链式存储 索引存储 散列存储 3.数据类型、抽象数据类型 ...
2022-04-24 08:51:57
485
原创 16.bufferevent客户端发送文件并处理超时和断开事件
linux下进行操作 makefile test:test.cpp g++ $^ -o $@ -levent ./$@ clean: rm -rf test rm -rf *.o 测试代码 #include <iostream> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #in
2022-04-24 07:07:54
463
原创 15.bufferevent客户端测试连接服务器
test.cpp #include <iostream> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #include <event2/bufferevent.h> #include <errno.h> #include <string.h> #ifndef _WIN32 #include <signa
2022-04-21 14:41:45
128
原创 14.buffferevent超时事件处理
test.cpp #include <iostream> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #include <event2/bufferevent.h> #include <errno.h> #include <string.h> #ifndef _WIN32 #include <signa
2022-04-21 14:19:27
356
原创 13.bufferevent接受和发送数据
test.cpp #include <iostream> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #include <event2/bufferevent.h> #include <errno.h> #include <string.h> #ifndef _WIN32 #include <signa
2022-04-20 21:18:49
362
原创 12.libevent循环函数和退出测试
test.cpp #include<iostream> #include<event2/event.h> #include<signal.h> using namespace std; bool isexit = false; //sock 文件描述符,which 事件类型,arg 传递参数 static void Ctrl_C(int sock, short which, void* arg) { cout << "Ctrl C" <<
2022-04-20 14:00:56
367
原创 11.libevent对水平触发和边缘触发测试
test.cpp #include <iostream> #include <thread> #include <event2/event.h> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #include <errno.h> #include <string.h> #ifndef _WIN32
2022-04-20 13:29:51
432
原创 10.libevent接收和处理服务器消息
test.cpp #include <iostream> #include <thread> #include <event2/event.h> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #include <errno.h> #include <string.h> #ifndef _WIN32
2022-04-20 09:06:15
360
原创 LeetCode367. 有效的完全平方数
题目传送门:367题 二分: class Solution { public: bool isPerfectSquare(int num) { int l=1,r=num; while(l<r) { int mid=(l+1ll+r)>>1; if(mid<=num/mid) l=mid; else r=mid-1; } re
2022-04-19 20:57:27
162
原创 09.使用libevent来读取登录日志并监听
test.cpp #include <iostream> #include <thread> #include <event2/event.h> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #ifndef _WIN32 #include <signal.h> #include <sys/types.h&
2022-04-19 14:48:44
196
原创 08.libevent定时器的优化
test.cpp #include <iostream> #include <thread> #include <event2/event.h> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #ifndef _WIN32 #include <signal.h> #else #endif using namesp
2022-04-19 14:18:06
346
原创 07.libevent定时器使用
test.cpp #include<iostream> #include<event2/event.h> #include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #ifndef _WIN32 #include <signal.h> #else #endif using namespace std; static timeval t
2022-04-19 13:54:15
255
原创 06.libevent在linux下信号事件处理
makefile test:test.cpp g++ $^ -o $@ -levent ./$@ clean: rm -rf test rm -rf *.o test.cpp #include<iostream> #include<event2/event.h> #include<signal.h> using namespace std; //sock 文件描述符,which 事件类型,arg 传递参
2022-04-19 07:57:10
206
原创 05.window上使用iocp
#include <event2/event.h> #include <event2/thread.h> #include<event2/listener.h> #ifndef _WIN32 #include <signal.h> #else #endif #include <iostream> using namespace std; #define SPORT 8080 void listen_cb(evconnlistener* ev, e
2022-04-18 20:39:28
390
原创 04.测试系统所支持的网络模型
代码验证 #include <event2/event.h> #include <signal.h> #include <iostream> using namespace std; int main() { #ifdef _WIN32 //初始化socket库 WSADATA wsa; WSAStartup(MAKEWORD(2, 2), &wsa); #else //忽略管道信号,发送数据给已关闭的socket if (signal(SIGPIP
2022-04-18 12:33:04
766
原创 03.libevent支持的网络模式测试
#include <event2/event.h> #include <iostream> #include <string.h> using namespace std; #define SPORT 8080 #ifdef _WIN32 #pragma comment(lib,"ws2_32.lib") #pragma comment(lib,"libevent.lib") #else #include <signal.h> #endif int m
2022-04-18 11:25:00
278
原创 LeetCode852. 山脉数组的峰顶索引
题目传送门:852题 class Solution { public: int peakIndexInMountainArray(vector<int>& arr) { int l = 0, r = arr.size() - 1; while (l < r) { int mid = l + r + 1 >> 1; if (arr[mid] > arr[mid - 1]) l =
2022-04-18 10:40:29
1093
原创 LeetCode35. 搜索插入位置
题目传送门:35题 class Solution { public: int searchInsert(vector<int>& nums, int target) { int l=0,r=nums.size(); //插入位置可能是nums.size()不用减1 while(l<r) { int mid=l+r>>1; if(nums[mid]>=target
2022-04-18 10:25:53
574
原创 02.linux下libevent配置
安装必要的环境 sudo apt install perl g++ make automake libtool unzip 编译zlib tar -xvf zlib* ./configure make make install 编译OpenSSL tar -xvf open* ./config make make install 编译libevent tar -xvf libevent* ./autogen.sh ./configure make make install 测试 makefile
2022-04-17 22:44:11
156
原创 LeetCode374. 猜数字大小
题目传送门:374题 class Solution { public: int guessNumber(int n) { int l = 1, r = n; while (l < r) { int mid = (long long)l + r >> 1; if (!guess(mid)) return mid; else if(guess(mid)<0) r=mid-1;
2022-04-17 21:39:07
628
原创 LeetCode704. 二分查找
题目传送门:704题 class Solution { public: int search(vector<int>& nums, int target) { int l=0,r=nums.size()-1; while(l<=r){ int mid=(r+l)>>1; if(nums[mid]==target) return mid; else if(num
2022-04-17 21:29:34
295
原创 02.数据结构之链表2
定义 typedef struct _Node { int data; struct _Node* next; }Node; Node* createList(); void insertList(Node* head, int data); void traverList(Node* head); int lenList(Node* head); Node* searchLisst(Node* head, int find); void deleteList(Node* head, Node* pf
2022-04-16 22:07:21
586
原创 3.c++引用浅谈
引用reference是一段内存空间的别名 引用规则 1 引用,是一种关系型声明,而非定义。不能独立存在,必须初始化,且与原类型保持一致,且不分配内存。 2 声明关系,一经声明,不可变更。 3 可对引用,再次引用。多次引用的结果,是某一变量具有多个别名,多个别名间是平行关系。 4 辨别引用与其它,&符号前有数据类型时,是引用,其它皆为取地址或按位与。 #include <iostream> using namespace std; int main() { int a=1, b=2;
2022-04-15 13:16:52
998
原创 01.libevent配置(初步)
环境配置:建立标准的开发环境目录,将所需的库,头文件等,放到对应的文件夹下,将项目放置到src目录下 选择项目属性配置:配置四个地方 #include <event2/event.h> #include <event2/listener.h> #include <iostream> #include <string.h> using namespace std; #define SPORT 8080 #ifdef _WIN32 #pragma c
2022-04-13 19:50:10
260
原创 2.c++函数重载
重载规则 1 函数名相同 2 参数个数不同,参数的类型不同,参数顺序不同 3 返回值类型,不作为重载的标准 #include <iostream> using namespace std; void func(int a) { printf("void func(int a)\n"); } void func(char a) { printf("void func(char a)\n"); } int main() { int a=0; func(a); //void func(
2022-04-13 12:02:53
297
原创 1.c++类型检查更加严格
c++拥有更加严格的类型检查 #include <stdio.h> #include <stdlib.h> int main() { const int a = 10; //int* pa = &a; //编译不能通过,必须得是const类型的 //char* p = malloc(100); //c++类型检查更加严格,编译不通过 int arr[2][3]; //int** pArr = arr; //无法从“int [2][3]”转换为“int **
2022-04-12 22:41:23
1312
原创 PAT1001题:A + B 格式
题目传送门1001题 #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; int c=a+b; string num=to_string(c); string res; for(int i=num.size()-1,j=0;i>=0;i--) { res=num[i]+res;
2022-04-11 22:45:33
110
原创 08.数据结构之广义表转二叉树
代码 typedef struct Node { char data; struct Node* lchild, * rchild; }Node; typedef struct Tree { Node* root; int length; }Tree; typedef struct Stack { Node** data; int top, size; }Stack; Node* getNewNode(char val) { Node* p = (Node*)malloc(sizeo
2022-04-11 12:19:00
321
原创 07.数据结构之二叉树
树的定义 typedef struct Node { int data; struct Node* lchild, * rchild; }Node; typedef struct Tree { Node* root; int length; }Tree; 创建树 Node* getNewNode(int val) { Node* p = (Node*)malloc(sizeof(Node)); p->data = val; p->lchild = p->rchild =
2022-04-11 09:05:05
769
原创 06.数据结构之栈(顺序表实现)
栈定义 typedef struct Stack { int* data; int top, size; }Stack; 栈的初始化 Stack* init(int n) { Stack* s = (Stack*)malloc(sizeof(Stack)); s->data = (int*)malloc(sizeof(int) * n); s->size = n; s->top = -1; return s; } 栈清空操作 void clear(Stack* s) {
2022-04-10 22:45:08
273
原创 05.数据结构之链队列
结点定义 typedef struct Node { int data; struct Node* next; }Node; 队列定义 typedef struct Queue { Node head;//虚拟头结点 Node* tail; int length; }Queue; 创建结点 Node* getNewNode(int val) { Node* p = (Node*)malloc(sizeof(Node)); p->data = val; p->next = NU
2022-04-06 15:34:21
101
原创 04.数据结构之循环队列(扩容版本)
队列的定义 typedef struct Queue { int* data; int lengeth; int head, tail, length; int count; }Queue; 取出队头元素操作 int front(Queue* q) { return q->data[q->head]; } 队列的初始化操作 Queue* init(int n) { Queue* q = (Queue*)malloc(sizeof(Queue)
2022-04-06 14:18:24
307
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅