随笔分类 -  c/c++

GCC 中零长数组,C99中的变长数组(VLA)
摘要:##GCC 中零长数组 GCC 中允许使用零长数组,把它作为结构体的最后一个元素非常有用,下面例子出自 gcc 官方文档。 struct line { int length; char contents[0]; }; struct line *thisline = (struct line *) m 阅读全文

posted @ 2020-11-26 11:07 ims- 阅读(403) 评论(0) 推荐(0)

二叉树前中后序遍历cpp
摘要:title #include <cstdio> #include <cstring> #include <iostream> using namespace std; /* 前序 HGEDBFCA, 中序 EGBD H FAC, 后序 EBDGACFH, root : H left : EGBD r 阅读全文

posted @ 2020-11-06 10:40 ims- 阅读(159) 评论(0) 推荐(0)

多进程测试共享内存原子变量
摘要:#include <atomic> #include <fcntl.h> /* For O_* constants */ #include <fstream> #include <iostream> #include <sys/ipc.h> #include <sys/shm.h> #include 阅读全文

posted @ 2020-10-30 16:13 ims- 阅读(453) 评论(0) 推荐(0)

字符串重复数量统计排序
摘要:统计并排序 数据:向map插入数据时候自增统计,完成对word数量的统计 sortPair原理 把map中的所有pair元素插入 vector,然后使用 sort,完成排序,效率低 queueSortPair 把map的元素插入数量有限的小端优先队列,比队列的最小值小的时候可以插入, 从而保存最大的 阅读全文

posted @ 2020-10-23 19:50 ims- 阅读(288) 评论(0) 推荐(0)

数据N个元素的和的组合
摘要:/* 写一个函数 void foo(arr, m, n),arr是整数数组,m是个数,n是和,打印所有和为n的 二维数组,注意兼顾性能。 例子: arr 为[-1,1,2,3,4,5,6] m=2, n=5时,打印 [ [1,4],[2,3],[-1,6] ] m=3, n=6时,打印[ [-1,1 阅读全文

posted @ 2020-10-19 21:47 ims- 阅读(253) 评论(0) 推荐(0)

c++ 一维数据传参引用
摘要:#include<iostream> using namespace std; #define LOG(str) printf("[%s][%s](%d)[%s][%s]:%s\n",__FILE__, __func__, __LINE__,__DATE__, __TIME__, str) temp 阅读全文

posted @ 2019-08-07 00:24 ims- 阅读(259) 评论(0) 推荐(0)

尾队列 tailq.h
摘要:[toc] 原理 https://my.oschina.net/u/2343729/blog/795059 阅读全文

posted @ 2019-07-05 22:41 ims- 阅读(275) 评论(0) 推荐(0)

c/c++取代switch的用法
摘要:1.常规switch enum EnumType { enumOne, enumTwo, enumThree }; void showMessage(int type) { switch(type) { case enumOne: printf("This is message one\n"); b 阅读全文

posted @ 2019-05-18 23:13 ims- 阅读(1369) 评论(0) 推荐(0)

gdb调试用法
摘要:@ 一、gdb功能简介 GDB主要帮忙你完成下面四个方面的功能: 1.启动你的程序,可以按照你的定制要求随心所欲的运行程序。 2.可让被调试的程序在你所指定的调置的断点处停住。 3.当程序被停住时,可以检查此时你的程序中所发生的事,以及内存状态等。 4.动态的改变你程序的执行环境。 二、gdb使用前 阅读全文

posted @ 2019-03-14 11:52 ims- 阅读(2719) 评论(0) 推荐(0)

Cmake用法
摘要:[toc] "cmake version 3.10 doc" 1,Cmake introduce CMake是一种跨平台编译工具,用来生成makefile。CMake主要是编写CMakeLists.txt文件,然后用cmake命令执行CMakeLists.txt文件生成make所需要的makefil 阅读全文

posted @ 2018-12-31 12:52 ims- 阅读(491) 评论(0) 推荐(0)

gtest 安装与使用
摘要:打开资源管理器: gtest 获取 从: 获取gtest 1.7.0 rc1.zip,下载链接,下载打包的源码 或在git仓库下载: gtest安装 下载gtest源码包:gtest 1.7.0.zip 解压后进入gtest 1.7.0目录 cmake CMakeLists.txt make 后生成 阅读全文

posted @ 2018-10-28 20:45 ims- 阅读(1671) 评论(0) 推荐(0)

导航