自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(112)
  • 收藏
  • 关注

原创 C++归并排序

#include<iostream>#include <vector>using namespace std;int nums[10] = {8, 5, 2, 3, 4, 6, 9, 1, 7, 10};int temp[10];//辅助数组void printArray(int a[],int n) { for (int i = 0; i < n; i++) { cout << a[i] << " "; }.

2021-01-29 16:40:49 170

原创 C++快速排序

#include<iostream>#include <vector>using namespace std;void printArray(int a[],int n){ for(int i=0;i<n;i++){ cout<<a[i]<<" "; }}void QuickSort(int *a,int start,int end){ int i=start; int j=end; i.

2021-01-29 15:59:42 161 1

原创 希尔排序

分组进行简单插入排序,一直分,一直分#include<iostream>#include <vector>using namespace std;void printArray(int a[],int n){ for(int i=0;i<n;i++){ cout<<a[i]<<" "; }}void Swap(int &a,int &b){ int tmp=a; a=b; .

2021-01-29 15:30:32 152

原创 C++插入排序

将一个一个数字插入到有序的序列中#include<iostream>#include <vector>using namespace std;void printArray(int a[],int n){ for(int i=0;i<n;i++){ cout<<a[i]<<" "; }}int main(){ int a[10]={8,5,2,3,4,6,9,1,7,10}; int tmp

2021-01-29 14:53:41 132

原创 C++选择排序

#include<iostream>#include <vector>using namespace std;void printArray(int a[],int n){ for(int i=0;i<n;i++){ cout<<a[i]<<" "; }}int main(){ int a[10]={2,5,8,3,4,6,9,1,7,10}; int tmp=0; for(int i=.

2021-01-29 14:36:15 88

原创 C++冒泡排序

#include<iostream>#include <vector>using namespace std;int main(){ int a[10]={2,5,8,3,4,6,9,1,7,10}; int tmp=0; int flag=0; for(int i=0;i<10&&(flag==0);i++){ flag=1; for(int j=0;j<10-i-1;j++){ .

2021-01-29 14:26:18 101

转载 2021-01-17

C++11新标准:decltype关键字一、decltype意义有时我们希望从表达式的类型推断出要定义的变量类型,但是不想用该表达式的值初始化变量(如果要初始化就用auto了)。为了满足这一需求,C++11新标准引入了decltype类型说明符,它的作用是选择并返回操作数的数据类型,在此过程中,编译器分析表达式并得到它的类型,却不实际计算表达式的值。二、decltype用法1.基本用法复制代码int getSize();int main(void){int tempA = 2;/*1.d

2021-01-17 22:35:34 70

转载 2021-01-17

C++11新标准:auto关键字一、auto意义编程时常常需要把表达式的值赋给变量,这就要求在声明变量的时候清楚地知道表达式的类型,然后要做到这一点并非那么容易。为了解决这个问题,C++11新标准引入了auto类型说明符,用它就能让编译器替我们去分析表达式所属的类型。二、auto用法1.基本用法复制代码int tempA = 1;int tempB = 2;/1.正常推断auto为int,编译通过/auto autoTempA = tempA + tempB;/2.正常推断auto为in

2021-01-17 22:34:16 94

原创 C++基础入门

C++基础入门1 C++初识1.1 第一个C++程序编写一个C++程序总共分为4个步骤创建项目创建文件编写代码运行程序1.1.1 创建项目​ Visual Studio是我们用来编写C++程序的主要工具,我们先将它打开[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZO6YTyMf-1610494973663)(assets/1541383178746.png)][外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PPWSd

2021-01-13 07:43:06 210 1

原创 C++核心编程

C++核心编程本阶段主要针对C++面向对象编程技术做详细讲解,探讨C++中的核心和精髓。1 内存分区模型C++程序在执行时,将内存大方向划分为4个区域代码区:存放函数体的二进制代码,由操作系统进行管理的全局区:存放全局变量和静态变量以及常量栈区:由编译器自动分配释放, 存放函数的参数值,局部变量等堆区:由程序员分配和释放,若程序员不释放,程序结束时由操作系统回收C++程序在执行时,将内存大方向划分为5个区域代码区:存放函数体的二进制代码,由操作系统进行管理的全局区: 全

2021-01-13 07:42:39 399

原创 C++提高编程

C++提高编程本阶段主要针对C++泛型编程和STL技术做详细讲解,探讨C++更深层的使用1 模板1.1 模板的概念模板就是建立通用的模具,大大提高复用性例如生活中的模板一寸照片模板:[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-09ltNEsI-1610494857909)(assets/1547105026929.png)]PPT模板:[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k8kbeenv-16104948579

2021-01-13 07:41:59 192

原创 C++字符串封装

main.cpp#include<iostream>#include"MyString.h"using namespace std;int main(){ String str1 = "aaa"; String str2 = "aaaa"; if (str1 == str2) { cout << "str1==str2"; } else { cout << "str1!=str2"...

2020-10-27 20:37:03 145

原创 C++11多线程 13.补充知识,线程池浅谈,数量谈,总结

#include<iostream>#include<mutex>#include<future>#include<atomic>#include<Windows.h>#include<list>using namespace std;class A{public: std::atomic<int> atm; A() { atm=0; //auto attm...

2020-09-07 14:49:49 197

原创 C++11 多线程编程 12.windows临界区、其他各种mutex互斥量

#include<iostream>#include<mutex>#include<future>#include<vector>#include<queue>#include<list>#include<Windows.h>//#define __WINDOWSJQ_//处于定义状态using namespace std;//本类用于自动释放windows下的临界区,防止忘记EnterCriticalS

2020-09-07 14:49:16 227

原创 C++11多线程 11.std::atomic续谈 std::async深入谈

#include<iostream>#include<thread>#include<mutex>#include<atomic>#include<future>using namespace std;//int g_mcount;std::atomic<int> g_mcount = 0;void muthread(){ for (int i = 0; i < 10000000; i++) { ...

2020-09-07 14:48:47 168

原创 C++11多线程编程 10.future其他成员函数、shared_future、atomic

#include<iostream>#include<thread>#include<future>#include<mutex>#include<vector>using namespace std;int mythread(){ cout << "mythred() start" << "thred id =" << std::this_thread::get_id() <<...

2020-09-07 14:47:24 198

原创 C++11多线程编程 9.async、future、packaged_task、promise

#include<iostream>#include<string>#include<thread>#include<asyncinfo.h>#include<future>#include<vector>using namespace std;class A{public: int mythread2(int mypar) { cout << mypar << ...

2020-09-04 00:50:40 214

原创 C++11多线程编程 8.condition_variable,,,wait,,,notify_one,,,notifu_all

#include<iostream>#include<thread>#include<vector>#include<string>#include<mutex>#include<list>using namespace std;class A{public: //把收到的消息(玩家命令)入到一个队列的线程。 void inMsgRecvQueue() { for (int i = 0;...

2020-09-04 00:50:09 180

原创 C++11多线程编程 7.单例设计模式共享数据分析、解决,call_once

#include<iostream>#include<string>#include<vector>#include<mutex>#include<thread>using namespace std;std::mutex resourece_mutex;std::once_flag g_flag;//这是一个系统定义的标记class mycas //这是一个单例类{ static void CreateInstance(...

2020-09-04 00:49:38 181

原创 C++11多线程编程 6.unique_lock详解

#include<iostream>#include<thread>#include<vector>#include<string>#include<mutex>#include<list>using namespace std;class A{public: //把收到的消息(玩家命令)入到一个队列的线程。 void inMsgRecvQueue() { for (int i = 0;...

2020-09-04 00:49:07 294

原创 C++11多线程编程 5.互斥量概念、用法、死锁演示及解决详解

#include<iostream>#include<thread>#include<vector>#include<string>#include<mutex>#include<list>using namespace std;class A{public: //把收到的消息(玩家命令)入到一个队列的线程。 void inMsgRecvQueue() { for (int i = 0;...

2020-09-04 00:48:33 180

原创 C++11多线程编程 4.创建多个线程,数据共享问题分析,案例代码

#include<iostream>#include<thread>#include<vector>#include<list>using namespace std;//线程入口函数vector<int>v = { 1,2,3 };//共享数据void myprint(int num){ cout << "线程开始执行了,线程编号=" << std::this_thread::get_id() &l...

2020-09-04 00:48:03 241

原创 C++11多线程编程 2.线程启动,创建,结束

#include<iostream>#include<thread>using namespace std;//自己创建的线程也要从一个函数(初始函数)开始执行void myprint(){ cout << "我的线程开始了1111" << endl; cout << "我的线程执行完毕了1111" << endl; cout << "我的线程开始了2222" << endl;...

2020-09-04 00:46:56 527

原创 C++11多线程编程 1.进程和线程基本概念

#include<iostream>#include<thread>using namespace std;int main(){ /*掌握概念一:并发,进程,线程的基本概念和综述 (1.1):并发和并行 两个或者更多的任务(独立的活动)同时发生(进行) (1.2):可执行程序 磁盘上的一个可以运行的文件,windo...

2020-09-04 00:46:21 295

原创 C++11 用wake_up解决循环引用

#include<iostream>using namespace std;/* 问题1:为什么会存在强弱指针的计数 问题2:强弱指针计数的用途是什么,具体的代码实现是什么。*/int main(){ std::shared_ptr<int> ptr(new int(5)); std::shared_ptr<int>ptr2 = ptr; std::weak_ptr<int> ptr3 = ptr; ...

2020-09-04 00:44:42 258

原创 C++11 shared_ptr和weak_ptr

#include<iostream>using namespace std;//share_ptr是带了引用计数的智能指针。void foo_constant(){ int* p = new int(3); std::shared_ptr<int> sptr(p); std::shared_ptr<int> sptr2(new int(4)); std::shared_ptr<int> sptr3 = sptr2;...

2020-09-03 01:37:00 232

原创 C++11 unique_ptr的使用

#include<iostream>#include<functional>#include<algorithm>#include<vector>#include<string>#include<deque>#include<list>using namespace std;void foo_constuct(){ //一般这种构造 std::unique_ptr<int> pt...

2020-09-03 01:36:30 427

原创 C++11 NULL与nullptr

#include"stdafx.h"#include<stdio.h>void foo(char* a){ int c = 10; printf("666");}void foo(int){ int b = 10; printf("777");}int main01(){ char* p = NULL; foo(NULL);//NUll为0,传入的参数相当于为int型的 foo(nullptr);//nullptr表示空指...

2020-09-03 01:35:34 125

原创 C++11 委托构造

#include<iostream>using namespace std;class Base{public: int value1; int value2; //无参构造 Base() { value1 = 1; } //如果不写:Base(),那么我们只能对value1或者value2赋初值 Base(int value) :Base()//在执行这个有参构造函数时候, ...

2020-09-03 01:34:09 318

原创 C++11 智能指针的原理

#include<iostream>using namespace std;//智能指针://1.用起来像指针(不是指针)//2.会自己对资源进行释放class CStudent{public: CStudent() { } void test() { cout << "CStudent" << endl; }private: char* m_pszBuf; int m_nS...

2020-09-03 01:33:37 111

原创 C++11 override重载虚函数,final

#include<iostream>using namespace std;//override 和final,还有编译器默认产生的各种构造的去与留default和delete//对于类的用法 final当前类作为最后一个类,不被继承//对于虚函数 final 当前虚函数到此为止,子类不能对这个虚函数进行重写。class Base{public: virtual void foo() final {} ; Base(int n) { /...

2020-09-03 01:32:00 276

原创 C++11 mutable

#include<iostream>using namespace std;//mutableint main00(){ int a = 10; //auto f = [a]() { // return ++a;//[a]只是单纯的将a捕获住了,a的性质仍然为const,不能修改,所以报错。 // //如果想要修改a的值,需要加关键字mutable //}; //按值捕获,所以内部的a无论如何修改都不会...

2020-09-03 01:27:47 308

原创 C++11 auto_ptr的使用及被废除的原因

#include<iostream>#include<vector>using namespace std;void foo_realse(){ int* Neew = new int(3); { std::auto_ptr<int> ptr(Neew); int* p = ptr.release();//释放指针的所有权,但是对应的指针不释放 //单纯的解除了...

2020-09-03 01:27:16 1722

原创 C++11函数对象包容器

#include<iostream>#include<functional>#include<vector>#include<string>#include<algorithm>using namespace std;int test(int n){ cout << n << endl; return 1;}class CTest{public: int Mytest(int ...

2020-09-03 01:26:33 260

原创 C++实现---哈希表,哈希函数以及线性探测,二次探测

#include<iostream>#include<time.h>#include<string>#include<math.h>#include<stdio.h>#define m 15//哈希表的表长#define NullKey 0 //单元为空的标记using namespace std;int HT[m] = {}, HC[m] = {};//HT是哈希表,HC是统计每个元素的插入时候的查找次数。并且初始化。int H

2020-09-03 01:18:15 842

原创 C++11lambda捕获

#include<iostream>#include<vector>#include<algorithm>using namespace std;//int main()//{// int a=10;// [a]() mutable{//两份内存,修改lambda里面的变量不影响外面的变量// a = a + 1;// cout << a << endl;// }();// ...

2020-08-19 02:51:13 751

原创 C++11 lambda的实现

#include<iostream>using namespace std;int main01(){ //lambda表达式就是匿名函数(没有名字的函数) //[]捕获列表 ()参数列表 ->返回值 {}函数主体 ()调用 int c=[](int a, int b)->int { return a + b; }(1,2); printf("%d", c); auto f= [](int a, int b)...

2020-08-19 02:49:57 144

原创 C++11 reinterpret_cast

#include<iostream>using namespace std;int main(){ //显示强转。 int n = 1; //int *p=(int *)n; //是一种显示强转,可读性更好 //适用于转换各种高危险的转换方式 //整形转指针, int* p = reinterpret_cast<int*>(n); //各种类型的指针转换(风险很高) char* pch = rei...

2020-08-19 02:48:55 200

原创 C++11dynamic_cast

//dynamic_cast主要用于虚函数的基类和派生类之间的指针或者引用的转换/*基类必须具有虚函数 原因:dynamic_cast是运行时类型检查,需要运行时类型信息,而这个信息是存储与类的虚函数表关系紧密,只有一个类定义了虚函数,才会有虚函数表。 运行时检查,转型不成功,则返回一个空指针。 非必要不要使用dynamic_cast,有额外的函数开销。 常见的转换方式: 基类指针或引用转派生类指针(必须使用dynamic_cast) ...

2020-08-19 02:48:24 392

原创 C++11Static_cast

#include<iostream>#include<string>using namespace std;//static_cast本质上就是明确隐式转换的,明确的作用//基类与派生类之间的转换class Cfather{public: Cfather() { m_ntest = 3; } virtual void foo() { cout << "cfather::void foo()" <&...

2020-08-19 02:47:38 921

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除