- 博客(13)
- 收藏
- 关注
原创 C++ volatile关键字
1、volatile关键字的作用volatile关键字修饰的变量是“易变的”,表示这个变量可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字修饰的变量时,编译器不能对访问该变量的代码进行优化,每次读取该变量的时候都只能从内存中读取,不能直接读取寄存器中的值。volatile int value :当要求使用 volatile 声明的变量的值的时候,系统总是重新从...
2019-10-17 20:04:33
232
原创 C++菱形继承、虚继承
1、菱形继承一个类由几个类派生得到,而这几类中有多个类又同时继承同一个类。如下图所示:Derive继承A、B,A、B又同时继承Base。class Base {public: char ch;};class A: public Base {public: char a;};class B : public Base {public: char b...
2019-10-12 21:15:12
224
原创 C++类的大小(sizeof)
1、空类class Base {};sizeof(Base)等于1。Base是一个空类,类在进行实例化的时候就是给一个实例分配一块内存,对一个空类进行实例化的时候,同样需要分配一块内存,编译器默认分配一个字节大小的内存给空类实例,所以空类的大小为一个字节。2、一般非空类class Base { int val; char ch;};sizeof(Base)...
2019-10-09 13:39:39
2645
1
原创 C++单例,线程安全,资源释放
//非线程安全;class Singleton {public: static Singleton& GetInstance() { static Singleton instance;//对象构造过程中可能线程切换到另一个线程; return instance; } void test() { cout << "test!!!" << endl...
2019-03-07 19:22:37
638
原创 C++ INT_MAX、INT_MIN、0x80000000以及int中负数的存储
一、INT_MAX、INT_MIN、0x8000000032位系统中int类型占4个字节,最大值为INT_MAX(或者0x7FFFFFFF),最小值为INT_MIN(或者0x80000000)。int main(){ int minInt = 0x80000000; int maxInt = 0x7FFFFFFF; cout << minInt << " ...
2018-12-14 20:33:40
3815
原创 快速排序、单向链表的快速排序(C++)
一、快速排序取数组的第一个值作为基准值key,将数组中小于key的值排在key的左边,将数组中大于key的值排在key的右边,然后递归处理以key为分割的两个序列(1)挖洞法。a、挖洞法就是将数组Array第一个值作为基准值key保存(索引left和right分别指向序列的头和尾元素),索引right从右至左移动找到第一个小于key值的元素或者left等于right(left==rig...
2018-11-09 20:33:18
3393
3
原创 《effective C++》读书笔记——02、#define,const,enum,inline
一、用const或enum替换#define(单纯常量)使用#define Con_num 1.55;后,预处理器会将代码中的Con_num替换成1.55。如果这个常量在程序中产生一个编译错误,编译的错误信息可能只提到1.55,而不是Con_num,可能会因为追踪这个而浪费时间。用const替代:const double Con_num = 1.55;使用常量可能比使用#define导...
2018-11-08 20:37:26
125
原创 890. Find and Replace Pattern
题目:You have a list of words and a pattern, and you want to know which words in words matches the pattern.A word matches the pattern if there exists a permutation of letters p so that after replaci...
2018-10-28 18:30:09
129
原创 515.Find Largest Value In Each Tree Row
题目:You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9] 题意是输入一个二叉树,找出二...
2018-10-26 20:42:26
142
原创 565.Array Nesting
题目:A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.S...
2018-10-25 21:28:39
209
原创 C++虚函数、虚函数表地址
总结自:https://blog.youkuaiyun.com/haoel/article/details/1948051/https://blog.youkuaiyun.com/qianghaohao/article/details/51356718编译器:VS2017一、虚函数当我们使用基类的引用或者指针调用一个虚成员函数时会执行动态绑定,直到运行时才知道到底调用了哪个版本的虚函数,被调用的函数是与绑定到...
2018-10-23 22:07:29
570
原创 C++:cin、cin.get()、cin.getline()、getchar()、getline()总结
一、cincin从输入缓冲区中读取数据,遇到结束符(Tab、Space、Enter)时输入结束,并且结束时结束符并不会丢弃,而是保留在输入缓冲区中。cin开始读取数据时遇到结束符时会直接忽略,也就是当输入缓冲区第一个数据为结束符时,cin会忽略并丢弃结束符。注意:当cin或者cin.get()与getline()同时出现时,需要注意缓冲区中的结束符。char ch1;cin >...
2018-10-21 21:31:53
492
原创 leetcode.853. Car Fleet
题目: N cars are going to the same destination along a one lane road. The destination is target miles away.Each car i has a constant speed speed[i] (in miles per hour), and initial position...
2018-07-12 13:15:49
523
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人