- 博客(120)
- 资源 (3)
- 收藏
- 关注
原创 链表成环问题
利用字节对齐判断链表是否有环,主要的思路就是根据字节对齐规则将字节空隙利用起来。利用字节空隙来标记遍历过的节点。 #include <stdio.h> //链表节点 struct Node{ int value; struct Node *next; }; //创建链表 struct Node* createNode(int n){ //头节点 struct Node *head = new struct Node; head->value =
2021-09-28 11:28:10
342
原创 手写队列、栈
//链表节点 struct Node{ int val; struct Node* next; }; //队列 class queue{ private: struct Node* top; //取数据端 struct Node* rear; //放数据端 int count; //元素个数计数器 public: queue(){ rear = new struct Node; rear->next = NULL;
2021-09-10 16:18:52
317
原创 二叉树的遍历
#include <stdio.h> #include <stdlib.h> #include <stack> using namespace std; struct Node{ int val; struct Node *left; struct Node *right; }; //先序递归遍历 void fdfs(struct Node *root){ if(root == NULL){ return;
2021-09-07 13:57:09
321
原创 Windows 多线程编程
#include<string> #include<iostream> #include<process.h> #include<windows.h> using namespace std; //声明互斥量句柄 HANDLE hmu; //线程绑定的函数返回值和参数是确定的,而且一定要__stdcall unsigned __stdcall threadFun(void *param) { WaitForSingleObject(hmu, I
2021-09-01 17:12:59
289
原创 信号量编程实现进程互斥
无信号量时 #include <stdio.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/sem.h> #include <sys/shm.h> #include <string.h> int main() { /*子进程*/ if(fork() == 0){ int n = 5; /*模拟对临界资源的访问*/
2021-08-20 15:26:50
273
原创 Linux popen函数的使用
#include <stdio.h> int main() { /*缓存数组*/ char buf[512] = {0}; /*将ls -l执行的结果写入管道*/ FILE *fp = popen("ls -l","r"); if(fp == NULL){ perror("popen"); return -1; } /*将结果从管道中读到缓存*/ fread(buf,1,sizeof(buf),f
2021-08-06 14:04:55
255
原创 Linux 使用文件锁实现多进程的文件互斥访问
#include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <sys/file.h> int main() { pid_t pid = fork(); //创建子进程 if(pid == -1){
2021-08-06 11:44:32
623
原创 C++ 单例模式
有缺陷的懒汉式 #include <iostream> using namespace std; class Single{ private: /*构造函数私有化*/ Single(){ cout<<"constructor created"<<endl; } /*禁用拷贝构造函数*/ Single(Single &) = delete;
2021-07-29 15:17:23
181
原创 Linux 时间戳获取及转换
#include <stdio.h> #include <time.h> int main() { time_t t; //时间戳 struct tm *p; time(&t); //获取时间戳 p=localtime(&t); //将时间戳转换为本地时间 printf("时间戳:%ld\n",t); printf("%d-%d-%d %d:%d:%d\n",(1900+
2021-07-21 13:48:09
567
原创 pugixml读写xml文件
pugixml包含三个文件,分别为pugixml.cpp,pugixml.hpp,pugiconfig.hpp.(没有的话需自行下载),使用时将这三个文件添加到工程中,并包含相应的头文件。编译时一定要编译pugixml.cpp文件。 实例代码 #include <iostream> using namespace std; #include "pugixml.hpp" #include "pugiconfig.hpp" using namespace pugi; bool ReadXm
2021-07-12 14:58:32
2497
原创 Linux网络编程
server.c #include <stdlib.h> #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <string.h> #include <unistd.h>
2021-07-02 23:03:14
165
原创 条件控制实现线程同步
#include <stdio.h> #include <pthread.h> #include <unistd.h> #include <stdlib.h> int data = 0; //互斥量 pthread_mutex_t mutex; //锁 pthread_cond_t cond = PTHREAD_COND_INITIALIZER; //创建条件变量,并用宏进行初始化 //线程t1处理函数 void *fun1(void *param)
2021-07-01 22:29:49
150
原创 线程同步之互斥量加锁解锁
不加锁的代码 #include <stdio.h> #include <pthread.h> #include <unistd.h> int data = 0; //互斥量 //线程t1处理函数 void *fun1(void *param){ for(int i=0;i<5;i++){ printf("t1 : data = %d\n",data++); sleep(1); } } //线程t2处理函数 void *fun2(voi
2021-07-01 20:44:22
172
原创 Linux多线程编程
#include <stdio.h> #include <pthread.h> //子线程任务 void *fun1(void *param) { static char *p = "\"my work has finished\""; //子线程返回数据 printf("t1:my id is %ld\n",(unsigned long)pthread_self()); printf("t1:param = %d\n",*((int
2021-06-29 22:03:12
158
原创 Linux进程间通信之信号携带消息
signalget.c #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> //信号捕获回调函数,软中断 void handler(int signum,siginfo_t *info,void *flag) { printf("sinum = %d\n",signum); //信号编号 if(flag!=NULL) //判断消
2021-06-29 00:00:52
359
原创 Linux进程间通信之共享内存
shmw.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> int main() { int shmid; key_t key; char *shmaddr;
2021-06-28 21:15:46
168
原创 Linux进程间通信之消息队列
进程1 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <string.h> //消息队列链表结点 struct msgbuf { long mtype; /* message type, must be > 0 */ char
2021-05-21 22:45:49
168
2
原创 Linux进程间通信之管道通信
匿名管道(用于亲缘进程间通信) #include <stdio.h> #include <stdlib.h> #include <fcntl.h> /* Obtain O_* constant definitions */ #include <unistd.h> int main() { int fd[2];//管道参数,fd[0]:读端,fd[1]:写端 char buf[1024] = {0}; if(
2021-05-21 15:27:09
166
原创 Linux文件光标移动
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int main() { int fd; //打开文件 fd = open("./demo1file",O_RDWR
2021-05-19 17:29:29
347
原创 Linux文件读取
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int main() { int fd; char *buf =(char *) malloc(15); //开辟15个字节
2021-05-19 17:02:38
323
原创 Linux文件写入
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int main() { int fd;//文件描述符 char *buf = "Linux filewrite";//要写
2021-05-19 16:36:11
426
2
原创 Linux打开及创建文件
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> int main() { int fd; //文件描述符 fd = open("./demo1file",O_RDWR|O_CREAT,0600);//如果文件不存在创建新的文件,0600表示可读可写权限 printf("%d\n",fd); return 0;
2021-05-19 15:36:42
206
原创 python 读取串口数据并绘制多路实时动态波形
import pyqtgraph as pg import numpy as np import serial import array from threading import Thread def Rx(): h = int.from_bytes(ser.read(1), 'little') #高8位 l = int.from_bytes(ser.read(1), 'little') #低8位 ans = (h << 8) + l #对ADC的值进行译码
2021-03-22 23:02:46
2637
3
原创 opencv实现人脸识别
解析全在注释里,opencv为第三方库,需要自己安装,安装方法: pip install opencv-python 其他必要的库请读者自行安装,这里不再赘述。opencv库中的方法精度并不是很高,影响因素非常多,可以采用降噪等方法提高精度。 开源的opencv库用于平时学习还是非常有帮助的,至于想做企业级产品还是建议另寻他法。 import cv2 import numpy as np import os import shutil import matplotlib.pyplot as plt #
2021-03-13 18:29:20
298
2
原创 Linux(树莓派)字符设备驱动编写、编译、测试
编写驱动代码 寄存器的操作参考芯片手册。 #include <linux/fs.h> //file_operations声明 #include <linux/module.h> //module_init module_exit声明 #include <linux/init.h> //__init __exit 宏定义声明 #include <linux/device.h> //class devi.
2021-03-11 16:06:34
251
原创 基于树莓派的Linux字符设备驱动框架
#include <linux/fs.h> //file_operations声明 #include <linux/module.h> //module_init module_exit声明 #include <linux/init.h> //__init __exit 宏定义声明 #include <linux/device.h> //class devise声明 #include <linux
2021-03-10 22:56:07
136
原创 使用交叉编译工具进行Linux内核(硬件平台-树莓派3b)编译
安装交叉编译工具链 sudo apt-get install gcc-arm-linux-gnueabihf 下载Linux内核源码 Linux内核源码下载 内核配置 使用厂家提供的config进行配置,树莓派1的工程是bcmrpi_defconfig;树莓派2、3的工程是bcm2709_defconfig。 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- KERNEL=kernel7 make bcm2709_defconfig 此命令功能是获取bcm2.
2021-03-10 21:54:58
290
原创 暴力破解WiFi密码
需要手动安装pywifi库(直接pip install pywifi的方法不行),手动安装方法自行百度。 import itertools as its import pywifi from pywifi import const import time import datetime # 测试连接,返回链接结果,pwd为密码,wifi_name为要破解的WiFi名称 def wifiConnect(pwd, wifi_name): # 抓取网卡接口 wifi = pywifi.PyWi
2021-03-10 13:40:24
5250
原创 跑步锻炼
import datetime start = datetime.date(2000,1,1) end = datetime.date(2020,10,1) dt = datetime.timedelta(days=1) #时间间隔为一天 cnt = 0 while start<=end: if start.weekday()==0 or start.day==1: cnt+=2 else: cnt+=1 start+=dt print(.
2021-03-04 21:26:26
153
1
原创 树莓派串口编程
初次使用树莓派串口编程,需要配置。 /* 修改 cmdline.txt文件 */ >cd /boot/ >sudo vim cmdline.txt 删除【】之间的部分 dwc_otg.lpm_enable=0 【console=ttyAMA0,115200】 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait /*修改 inittab文件 */
2021-03-03 14:28:43
165
1
原创 wiringPI库实现继电器操作
#include <stdio.h> #include <wiringPi.h> int main() { if(wiringPiSetup ()==-1){ //硬件初始化函数 printf("初始化失败!\n"); return -1; } pinMode (7, OUTPUT);//io口模式设置 digitalWrite(7,HIGH);//输出高
2021-03-03 12:19:33
131
原创 python绘制矩阵热力图
import seaborn as sns import pandas as pd import matplotlib.pyplot as plt df = pd.read_excel(r'D:\xxx.xlsx').set_index('xxx') fig, ax = plt.subplots(figsize = (9,9)) sns.heatmap(df,annot=True, vmax=1,vmin = 0, xticklabels= True, yticklabels= True, square
2021-02-08 14:33:57
1313
2
原创 networkx绘制有向图
import pandas as pd import matplotlib.pyplot as plt import networkx as nx G = nx.DiGraph() df = pd.read_csv('data.csv').set_index('xxx') nodes = [] edges = [] cnt = 0 groupd = df.groupby('xxx') for name,group in groupd: if cnt == 80: break
2021-02-06 20:59:56
1585
原创 基于sklearn库的神经网络进行预测
from sklearn.neural_network import MLPRegressor import numpy as np mlp = MLPRegressor(solver='lbfgs',hidden_layer_sizes=(3,2),activation='logistic') X = np.array([ [-2, -1], # Alice [25, 6], # Bob [17, 4], # Charlie [-15, -6], # Diana ]
2021-02-05 00:43:21
1545
2
原创 python 求解非线性规划问题
题目: 代码: from scipy.optimize import minimize import numpy as np from mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt # 目标函数: def func(x): return 10 - x[0] ** 2 - x[1] ** 2 # 约束条件,包括等式约束和不等式约束 def con(): cons = ({'type':
2021-01-22 16:18:15
1164
原创 相关性分析(求相关系数)
代码 import matplotlib.pyplot as plt import numpy as np plt.figure() # 数据集 x = [75, 70, 65, 60, 55, 50, 45, 40, 35, 30] y = [22.44, 92.17, 31.74, 51.37, 20.92, 20.67, 20.32, 90.05, 19.84, 19.59] r = np.corrcoef(x,y)[0][1] print('相关系数r=',r) # 绘制散点 plt.scatte
2021-01-15 17:41:39
837
原创 单元拟合(以线性拟合为例)
import numpy as np import matplotlib.pyplot as plt from scipy import optimize def f_1(x, a, b): return a * x +b plt.figure() # 拟合点 x0 = [75, 70, 65, 60, 55, 50, 45, 40, 35, 30] y0 = [22.44, 22.17, 21.74, 21.37, 20.92, 20.67, 20.32, 20.05, 19.84, 19
2021-01-15 16:39:48
241
原创 平均值、方差、标准差
import numpy as np arr = [1,2,3,4,5,6,7,8,9,10] avrege = np.mean(arr) #求平均值 f_var = np.var(arr) b_var = np.std(arr) print("平均值为:",avrege) print("方差:",f_var) print("标准差:",b_var)
2021-01-15 15:26:07
293
原创 样条插值法
一维插值法 代码 import numpy as np from scipy import interpolate import pylab as plt x=np.linspace(0,10,11) y=np.cos(x) xnew=np.linspace(0,10,51) plt.plot(x,y,"ro") #红色圆点 for kind in ["nearest","zero","slinear","quadratic","cubic"]:#插值方式 #"nearest","zero"为
2021-01-14 17:45:48
917
1
原创 蒙特卡洛法(随机取样法)
y=x^2、y = 12 − x与x 轴 在第一象限围成一个曲边三角形。设计一个随机试验,求该图像面积的近似值。 解: 设计的随机试验思想如下:在矩形区域 [0, 12] * [0, 9] 上产生服从均匀分布的 10^6 个随机点,统计随机点落在曲边三角形的频数,则曲边三角形的面积近似为上述矩形面积乘于频率。 代码 import random #random.random()产生的是0~1的随机数 x = [random.random() * 12 for i in range(0, 10**6)] y =
2021-01-14 16:07:04
1630
ChatSystem.zip
2020-08-19
研究生信息管理系统.zip
2020-04-15
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅