C/C++
我没有那种天分
我一无所知
展开
-
管理全局唯一变量的类(单例模式)
template<typename T>class Singleton {public: static T* instance() { return _s_instance; }protected: Singleton() {} virtual ~Singleton() {}private: //only declare; forbiden copy and assign Singleton(const Singleton.原创 2020-08-16 15:31:49 · 437 阅读 · 0 评论 -
C++实现一个简单的线程池
ThreadPool.h#pragma once#include <iostream>#include<stdlib.h>#include<thread>#include<mutex>#include<condition_variable>#include<vector>#include<funct...原创 2020-04-26 23:00:53 · 219 阅读 · 0 评论 -
二分查找问题(BinarySearch, Floor, Ceil)
二分查找是很基本的查找算法,但二分查找的变种问题(floor, ceil)也很重要,并且不那么简单。原创 2020-03-14 12:40:31 · 202 阅读 · 0 评论 -
冒泡,插入,归并,快速排序(优化)
冒泡排序如何优化?插入排序比一般的O(n2)的排序算法要好,因为它会提前终止;递归排序和快速排序有个优化点。原创 2020-03-19 15:28:08 · 203 阅读 · 0 评论 -
堆排序(shiftDown, shiftUp, heapify)
堆排序的过程包含shiftDown, shiftUp, heapify原创 2020-03-20 09:10:47 · 1060 阅读 · 0 评论 -
使用迭代实现二叉树的前中后序遍历(C++)
使用递归实现二叉树的前中后序遍历很简单,写法基本相同。但用迭代稍有不同,较递归稍难理解和记忆,但迭代效率更高。下面是用迭代实现二叉树的前中后序遍历的代码示例。#include <iostream>#include <vector>#include <stack>using namespace std;//Definition for a bina...原创 2020-01-18 17:27:52 · 1053 阅读 · 1 评论 -
C++实现int转char*和char*转int
#include <iostream>#include <string.h>using namespace std;/***将字符串转成int***/int char2int(const char* str) { const char* p = str; bool neg = false; int res = 0; if (*str...原创 2020-01-03 16:13:49 · 5686 阅读 · 1 评论 -
32位的Int转成长度为4的8位Char数组
int num = 9999;char c[4] = {0};方法一:使用memcpy函数,需要注意大小端问题memcpy(c, (char*)&num, 4)结果:c[0] = 15, c[1] = 39, c[2] = 0, c[3] = 0 方法二:位操作c[3] = num & 0xFF;num = num >> 8;c[2]...原创 2018-11-25 21:43:46 · 2483 阅读 · 1 评论 -
C语言各进制表示
C语言中:十进制直接表示,例如:1,2,3,4,5,6 八进制要加零表示,例如:00,01,02,03,04,05 十六进制要加0x表示,例如:0xA1,0x13,0xFF原创 2017-03-29 22:02:12 · 10661 阅读 · 1 评论 -
生成连续的不限长度的数字字符串
#include <string>#include <iostream>using namespace std;class NumString{public: NumString() { m_str = '0'; m_iLenght = 1; } ~NumString() { }public: NumString& opera...原创 2018-10-28 12:55:26 · 310 阅读 · 0 评论 -
Linux C多线程编程
场景:对于一个status = 0, 线程1会修改status, 线程2会读取status,如果status为0则阻塞,如果非0则继续执行。pthread_mutex_t mutex;pthread_cond_t cond;status = 0;void thread1_fun(void* arg){ pthread_mutex_lock(&mutex); ...原创 2018-10-22 23:21:09 · 136 阅读 · 0 评论 -
常见C++面试题及基本知识点总结
转自:http://www.cnblogs.com/LUO77/p/5771237.html 1. 结构体和共同体的区别。定义:结构体struct:把不同类型的数据组合成一个整体,自定义类型。共同体union:使几个不同类型的变量共同占用一段内存。地址:struct和union都有内存对齐,结构体的内存布局依赖于CPU、操作系统、编译器及编译时的对齐选项。关于内...转载 2018-10-19 16:21:43 · 154 阅读 · 0 评论 -
C++虚函数表解析
转自:https://www.cnblogs.com/hushpa/p/5707475.html先看代码:#include <iostream>using namespace std;class Base {public: virtual void f() {cout<<"base::f"<<endl;} virtual vo...转载 2018-10-16 20:39:00 · 169 阅读 · 0 评论 -
C++中的静态绑定和动态绑定(多态)
C++具有多态的特性,理解多态原理需要理解以下四个概念。 1、对象的静态类型(static type):就是它在程序中被声明时所采用的类型(或理解为类型指针或引用的字面类型),在编译期确定; 2、对象的动态类型(dynamic type):是指“目前所指对象的类型”(或理解为类型指针或引用的实际类型),在运行期确定; 这两个概念一般发生在基类和派生类...原创 2018-10-18 22:09:46 · 5105 阅读 · 0 评论 -
C++变量的存储位置
void main(){ int b; //栈 char s[] = "abc"; //栈 char *p1,*p2; //栈 char *p3 = "123456"; //123456在常量区,p3在栈上 static int c = 0; //全局(静态)初始化区 p1 = (char *)malloc(10); //分配得来得10字节的区域...原创 2018-08-06 20:56:26 · 356 阅读 · 0 评论