
C/C++
youngqqcn
精通区块链C/C++/Python/Golang/Rust/Solidity。联系:youngqqcn@qq.com
展开
-
01背包问题
01背包问题(二维数组)https://mp.weixin.qq.com/s/FwIiPPmR18_AJO5eiidT6w/*再回顾一下dp[i][j]的含义:从下标为[0-i]的物品里任意取,放进容量为j的背包,价值总和最大是多少。那么可以有两个方向推出来dp[i][j],由dp[i - 1][j]推出,即背包容量为j,里面不放物品i的最大价值,此时dp[i][j]就是dp[i - 1][j]由dp[i - 1][j - weight[i]]推出,dp[i - 1][j - wei原创 2021-08-04 15:00:37 · 154 阅读 · 0 评论 -
STL所有算法汇总
#include <iostream>#include <algorithm>#include <string>#include <vector>#include <set>#include <random>using namespace std;/*查找算法(13个):判断容器中是否包含某个值 adjacent_find: 在iterator对标识元素范围内,查找一对相邻重复元素,找到则返回指向这对元素的原创 2021-07-18 17:52:22 · 120 阅读 · 0 评论 -
记录一个问题_char**和 char[][]
ubuntu 20.04不能用 使用 char** ,$ gcc --versiongcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0Copyright (C) 2020 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or F原创 2021-07-16 19:04:36 · 249 阅读 · 0 评论 -
C++11/14/17 新特性总结
C++11/14/17 新特性总结initializer_list std::vector<int> vctInts({92, 12, 39, 46, 92, 84, -1, 0, -234});auto std::vector<int> vctInts({92, 12, 39, 46, 92, 84, -1, 0, -234}); for (const auto& item : vctInts) { std::cout << item原创 2021-06-03 09:50:06 · 710 阅读 · 0 评论 -
C++11 并发编程
C++11 并发编程参考书籍: https://chenxiaowei.gitbook.io/c-concurrency-in-action-second-edition-2019/开启线程#include <iostream>#include <thread> // 1void hello() // 2 { std::cout << "Hello Concurrent World\n";}int main(){ std::thread原创 2021-06-01 15:31:16 · 280 阅读 · 0 评论 -
现代C++ moderncpp
#include <iostream>#include <memory>#include <string>int main(int argc, char const *argv[]){ // ISO C++ forbids converting a string constant to ‘char*’ char *p = "this is const string"; char pStr[] = "this is test";原创 2021-05-28 11:12:54 · 419 阅读 · 0 评论 -
Redis简单使用(C++)
use_redis.h#ifndef _REDIS_H_#define _REDIS_H_#include <iostream>#include <string.h>#include <string>#include <stdio.h>#include <hiredis/hiredis.h>class Redis{ public: Redis(){} ~Redis() { this->_conn原创 2021-05-28 11:08:44 · 702 阅读 · 0 评论 -
MongoDB简单使用(C语言)
#include <bson.h>#include <mongoc.h>#include <stdio.h>intmain (int argc, char *argv[]){ mongoc_client_t *client; mongoc_collection_t *collection; bson_error_t error; bson_oid_t oid; bson_t *doc; mongoc_init (); client = m原创 2021-05-27 10:06:06 · 743 阅读 · 0 评论 -
memcache简单使用(C++)
mem.h#ifndef MEMCACHEDCLIENT #define MEMCACHEDCLIENT #include <libmemcached/memcached.h>#include<iostream>#include<string.h>#include<time.h>#include <stdlib.h>#include <stdio.h> using std::string;using std:原创 2021-05-27 10:05:37 · 633 阅读 · 0 评论 -
图的表示方法
图图的描述方式:邻接矩阵邻接链表邻接矩阵实现#pragma once#include "graph.h"#include <vector>#include <iostream>#include <iomanip>#include <queue>#include <exception>//#include <string>#define NPOS -1template <typename V,原创 2021-05-21 11:19:46 · 154 阅读 · 0 评论 -
前缀树(Trie)
Trie (前缀树)Trie.hpp/***@time: 2019-11-15 15:43:13*@author: yqq*@descriptions: 实现前缀树*/#ifndef __TRIE_H__#define __TRIE_H__#include <map>#include <string>template < class CharT = char, class StringT = std::string>class T原创 2021-05-21 11:20:47 · 130 阅读 · 0 评论 -
红黑树(RBTree)
RBTree#pragma once#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <string>#include <algorithm>#include <vector>#include <list>#include <map>#include <原创 2021-05-21 11:20:26 · 402 阅读 · 0 评论 -
二分查找树(BST)
BinarySerachTree#pragma once#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <string>#include <algorithm>#include <vector>#include <list>#include <map>#i原创 2021-05-21 11:17:04 · 606 阅读 · 0 评论 -
平衡二叉树AVLTree
AVLTree#pragma once/***@time: 2019-10-28 18:43:40*@author: yqq*@descriptions: 平衡二叉树*///参考 : https://www.tutorialspoint.com/cplusplus-program-to-implement-avl-tree#include <iostream>#include <stdio.h>#include <string.h>#incl原创 2021-05-21 11:16:42 · 128 阅读 · 0 评论 -
C++20-协程(coroutine)
参考: https://en.cppreference.com/w/cpp/language/coroutinesCoroutinesA coroutine is a function that can suspend execution to be resumed later. Coroutines are stackless: they suspend execution by returning to the caller and the data that is required to res原创 2021-02-05 11:53:48 · 921 阅读 · 0 评论 -
c++11实现线程池
https://github.com/youngqqcn/ThreadPoolclass ThreadPool{public: // the constructor just launches some amount of m_vctWorkers ThreadPool(size_t nThreads = std::thread::hardware_concurrency()) : stop(false) { if (nThreads <=原创 2021-02-04 14:26:12 · 359 阅读 · 0 评论 -
开始使用c++20
这里包含了各编译对c++标准的实现进度:https://en.cppreference.com/w/cpp/compiler_support这里以g++10为例, 关于怎么安装g++10可以参考这篇文章#include <bit>#include <iostream> int main() { if constexpr (std::endian::native == std::endian::big) { std::cout <<原创 2021-01-25 15:13:35 · 883 阅读 · 2 评论 -
linux安装多个版本gcc和g++
https://askubuntu.com/questions/26498/how-to-choose-the-default-gcc-and-g-version删除update-alternatives中旧的gcc和g++配置:sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++安装It seems that both gcc-4.3 and gcc-4.4 are insta原创 2021-01-25 15:00:15 · 1535 阅读 · 0 评论 -
有序数组合并merge
#include <stdio.h>#include <limits.h>#define NUMCOUNT 10int nums[NUMCOUNT];int snums[NUMCOUNT];#define THRDCOUNT 2void merge(){ int idx[THRDCOUNT]; int pernum = (NUMCOUNT/THRDCOUNT); for(int i = 0; i < THRDCOUNT; i++)原创 2021-01-17 15:36:18 · 147 阅读 · 0 评论 -
C++类的构造函数初始化列表执行顺序
class A{public: A(int a, int b) :_m_a(a),_m_b(_m_a * 2) // 不规范! 不应该依赖初始化的执行顺序! { }private: int _m_b; int _m_a;};class A{public: A(int a, int b) :_m_a(a),_m_b(a * 2) // ok { }private: int _m_b; int _m_a;};...原创 2021-01-10 20:43:22 · 276 阅读 · 0 评论 -
boost的circular_buffer 使用
#include <boost/circular_buffer.hpp>#include <iostream>int main(int argc, char const *argv[]){ boost::circular_buffer<int> buf; buf.resize(3); buf.push_back(1); buf.push_back(2); buf.push_back(3); buf.push_b原创 2021-01-10 17:47:32 · 345 阅读 · 0 评论 -
C++多态与模板结合
以下代码摘自muduo库, 实现的很漂亮, 非常值得学习 , 具体说明可以参考(书<<Linux多线程服务端编程–使用muduo C++网络库>>的P234-P235)dispatcher.h// Copyright 2011, Shuo Chen. All rights reserved.// http://code.google.com/p/muduo///// Use of this source code is governed by a BSD-style原创 2021-01-01 22:58:02 · 447 阅读 · 0 评论 -
fork的注意事项
在fork是需要注意父进程中的哪些资源是会被子进程继承的用于管理动态内存和文件描述符的RAII类可以正常工作#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <string.h>#include <fcntl.h> // openpid_t g_parent_pid = 0;#define NEW_BUF_SIZE 6// 子进程会继承原创 2020-11-29 16:18:09 · 278 阅读 · 0 评论 -
__thread 变量使用
__thread 使用规则:只能修饰POD类型, 不能修饰class类型, 因为无法自动调用构造函数和析构函数__thread可以修饰全局变量和函数内的静态变量, 但是不能修饰函数的局部变量或者class的普通成员变量.#include <stdio.h>#include <pthread.h>#include <unistd.h>#include <string.h>#include <string>#define THRE原创 2020-11-29 12:26:20 · 1183 阅读 · 3 评论 -
qt+vs2017 使用 vs2015编译报错 'type_traits': No such file or directory
Win7下 qt + vs2017 使用 vs2015编译报错'type_traits': No such file or directory“cl”不是内部或外部命令,也不是可运行的程序或批处理文件问题原因: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat 中有两行检查命令, 检查命令失败导致...原创 2019-12-09 11:15:01 · 6004 阅读 · 0 评论 -
vs2015(或vs2017) 不能新建C++项目
前段时间安装 nodejs的一些模块&nbsp;, 添加了环境变量&nbsp;&nbsp;VCTargetsPath, 并设置为 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140, 并添加到了系统path中.&nbsp;&nbsp;&nbsp;结果导致vs2015不能新建c++项目(创建出来的项目没有文件,只有"外部依赖&quo原创 2018-12-24 10:54:22 · 16090 阅读 · 3 评论 -
二维数组作函数参数
第一种函数形参的写法: #include #define R 5 // 行数#define C 5 // 列数void printMatrix ( int a[ ][C] , int row, int column ) // 使用 int a[R][C] 也可以 , 但是 int a[][] ,就不行!{ int i , j; for ( i = 0; i < row; i+原创 2016-09-03 19:57:03 · 641 阅读 · 0 评论