C++
我爱吃炒粉
新手
展开
-
C++Thread-带返回值的线程处理函数
#include <iostream>#include <thread>#include <chrono>#include <future>using namespace std;//用asyncint returnval(){ return 100;}void test01(){ future<int> ret=async(returnval); cout << ret.get(); }//打包.原创 2022-03-24 23:09:10 · 2364 阅读 · 1 评论 -
C++创建多线程
#include <iostream>#include <thread>using namespace std;//带参函数void print(int num){ cout << "num=" << num << endl;}void test01(){ thread t1(print, 10); t1.join();}//无参函数void print2(){ cout << "无参" <&.原创 2022-03-21 22:47:28 · 575 阅读 · 0 评论 -
C++AVL
#include <stdio.h>#include <stdlib.h>#include <assert.h>#define HEIGHT(p) ((p==NULL)?-1:(p->height))#define MAX(a,b) ((a)>(b)?(a):(b))typedef struct { int key; char info[20];}DATA,*LPDATA;typedef struct AVLTreeNode { D.原创 2022-03-06 00:23:13 · 523 阅读 · 0 评论 -
C++BinarySearchTree
#include<iostream>#include<string.h>#include<string>using namespace std;class Data{public: Data() = default; Data(int key, string val):key(key),val(val){} void PrintData() { cout << this->key << " " << .原创 2022-03-02 00:17:08 · 123 阅读 · 0 评论 -
heap(c)
#include<stdio.h>#include<stdlib.h>#include<time.h>typedef struct{ int* mem; int cursize; int maxsize;}HEAP,*LPHEAP;LPHEAP creatheap(int maxsize){ LPHEAP newheap=(LPHEAP)malloc(sizeof(HEAP)); newheap->cursize = 0; newh.原创 2022-02-19 19:00:43 · 227 阅读 · 0 评论 -
数组hash
#pragma once#include<iostream>using namespace std;class hashs{public: hashs(int max) { this->maxsize = max; this->cursize = 0; this->num = new int[max]; for (int i = 0; i < max; i++) { this->num[i] = '\n'; } }.原创 2022-02-17 20:56:29 · 668 阅读 · 0 评论 -
BF算法(c++)
int bf(str s) { int i = 0, j = 0, index = 0; while (arr[i] != '\0' && s.arr[j]!='\0') { if (arr[i] == s.arr[j]) { i++; j++; } else { index++; i = index; j = 0; } } if (s.arr[j] == '\n') { retu..原创 2022-02-15 08:18:08 · 719 阅读 · 0 评论 -
自写串(c++)
#pragma once#define MAX 1024using namespace std;class str{public: str() { this->arr = new char[MAX]; for (int i = 0; i < MAX; i++) { arr[i] = '\0'; } this->cursize = 0; } void insert(int pos,const char c[]) { int n = str.原创 2022-02-15 07:40:41 · 304 阅读 · 0 评论 -
自写button(可扩增)
#pragma once#include<easyx.h>using namespace std;class mybutton{public: mybutton(int x1, int y1, int x2, int y2) :x1(x1), y1(y1), x2(x2), y2(y2) {} void putbutton() { solidrectangle(x1, y1, x2, y2); } const string text; int x1; int y1;.原创 2022-01-24 20:40:44 · 49 阅读 · 0 评论 -
双向循环链表
#pragma onceusing namespace std;template<class ty>struct node{ node(node*pfront,ty t,node*ptail) { this->front = pfront; this->t = t; this->tail = ptail; } node() { this->front = this; this->tail = this; } node.原创 2022-01-17 21:58:20 · 378 阅读 · 0 评论 -
自写顺序表
#pragma onceusing namespace std;template<class ty>class Orders{public: Orders(int max) { this->Arr = new ty[max]; this->Cursize = 0; this->Maxsize = max; } void Add(ty x); void print(); void deletes(ty x); ~Orders() { .原创 2022-01-11 21:26:43 · 218 阅读 · 0 评论 -
C++时间管理
头文件:chrono#include<chrono>时钟:1.system_clock(系统时钟)2.steady_clock(稳步时钟)3.high_resolution_clock(高精度时钟)三种时钟使用方法相同1.时间段的演示案例#include<iostream>#include<chrono>using namespace std;int main(){ chrono::hours(1);//1小时 chron原创 2022-01-06 00:23:06 · 1141 阅读 · 0 评论 -
C++智能指针和正则表达式
1.智能指针头文件:memory#include<memory>本质:一个类shared_ptr(共享形智能指针)#include<iostream>#include<memory>using namespace std;int main(){ shared_ptr<int> ps(new int(1)); }get()函数-返回对象管理的内存的指针#include<iostream>#inc原创 2022-01-04 21:45:58 · 491 阅读 · 0 评论 -
C++STL算法篇(下)
next_permutation:下一个排序序列的组合 #include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ vector<int> v = { 1,3,6,8,6,6,2,0,9,0 }; next_permutation(v.begin(), v.end());//下一个排序序列的组合 for (auto v..原创 2022-01-03 03:09:23 · 76 阅读 · 0 评论 -
C++STL容器篇(中)
list(双向链表)头文件:list创建方式如下int main(){ list<int> l;}stack(栈)头文件:stack创建方式如下int main(){ stack<int> s;}队列头文件:queue1.单向队列(queue)#include<iostream>#include<queue>using namespace std;int main(){ queue&l原创 2022-01-03 00:20:47 · 438 阅读 · 0 评论 -
C++STL迭代器
1.迭代器:类中类正向迭代器只能正向不能反向#include<iostream>#include<vector>using namespace std;int main(){ vector<int> v; v.push_back(10); v.push_back(20); v.push_back(30); v.push_back(40); vector<int>::iterator it;原创 2021-12-28 23:27:13 · 348 阅读 · 0 评论 -
C++继承和派生
继承的基本语法:class类名:继承方式 父类,继承方式 父类......可以写多个父类,示例如下#include<iostream>using namespace std;class father{};class mother{};class son :public father, protected mother{};int main(){ return 0;}继承后,父类中的属性子类也会有一份,继承方式一共有三种:公共继承(publi原创 2021-12-20 22:12:01 · 277 阅读 · 0 评论 -
C++STL容器篇(三)
1.set与mulsetset(集合):数据自动去重,自动排序,默认从小到大,创建方式如下#include<iostream>#include<set>using namespace std;int main(){ set<int> s; s.insert(10); s.insert(10); s.insert(30); s.insert(20); for (set<int>::iterator it = s.begin();原创 2021-12-19 22:25:51 · 660 阅读 · 0 评论 -
C++类的组合
类的组合:套娃class a{public: int a;};class b{public: a p; int b;};如上,类b里有个a#include<iostream>using namespace std;class a{public: int a;};class b{public: a p; int b;};int main(){ b b1; b1.p.a = 10; return 0;}类可原创 2021-12-19 15:37:05 · 497 阅读 · 0 评论 -
C++运算符重载
运算符重载原创 2021-12-19 15:22:41 · 671 阅读 · 0 评论 -
C++的特殊成员
const成员class person{public: void printc() const { cout << "hi" << endl; } int m_a;};如上,类中的函数后加了const修饰便为const的成员函数,若加了const修饰则该函数里面不能对值进行修改。若重复名,普通对象默认调用普通函数无法调用const函数,若只有const函数则普通对象可以调用const函数。const对象不能调用普通函数只能调用const修饰的函数st原创 2021-11-29 22:42:15 · 236 阅读 · 0 评论 -
构造函数和析构函数
构造函数:写法:类名()person(){}可以采用初始化参数列表的写法person(int a,int b):m_a(a),m_b(b){}若不写构造函数则有默认的午餐构造函数默认的无参构造函数可以用delete删除class person{public: person() = delete; int m_a;}也可以自己用default写系统默认的无参构造函数class person{public: person() = defau原创 2021-11-29 22:16:23 · 476 阅读 · 0 评论 -
自写Array类
#include<iostream>#include<iostream>using namespace std;class Array{public: Array(int num) :size(num) { if (num) { this->pArr = new int[num]; } } Array(const Array& a) :size(a.si...原创 2021-11-28 00:14:15 · 61 阅读 · 0 评论 -
C++类和对象
创建语法:classclass person{public://公共权限 void printage() { cout << m_age << endl; }void addage(int age) { m_age=age; }protected://保护权限private://私有权限 int m_age;};如上为定义类,其中public,protected,private为权限限定词,类外只可访问public作用域下,若不写则默认原创 2021-11-18 22:49:10 · 327 阅读 · 0 评论 -
【无标题】 C++和C的区别(二)
C++和C的区别原创 2021-11-16 22:43:05 · 318 阅读 · 0 评论 -
关于C++与C的区别(一)
A.头文件和空间名 1.头文件的区别 a.c语言的头文件可以省略".h"但要在前面加个c,如"stdio.h"->cstdio"#include<stdio.h>//写法1#include<cstdio>//写法2//在cpp中,可以有两种写法,c语言只能用写法1 2.空间名 a.空间的定义:namespace 空间名...原创 2021-11-14 17:10:57 · 437 阅读 · 1 评论