自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(27)
  • 问答 (1)
  • 收藏
  • 关注

原创 顺序表简单功能实现(C++)

顺序表简单功能实现:#include<iostream>using namespace std;typedef int DataType;#define MAX 100//#pragma warning(disable:6385)//#pragma warning(disable:6386)//#pragma warning(push)//#pragma warning(pop)class List{public: void InitList(); void Lengt

2021-11-08 00:31:50 123 1

原创 斐波那契数列(c++)

菲波那切数列:#include<iostream>using namespace std;#include<vector>class mathline{public://确定递推式 int p(int N) { if (N <= 1) return N; vector<long double>dp(N + 1);//dp数组的空间为N+1 //dp数组的初始化 dp[0] = 0; dp[1] = 1; for (in

2021-11-05 19:45:43 726

原创 快速排序的实现(c++)

快速排序如下:#include<iostream>using namespace std;#define MAX 100int arr[MAX];void quickSort(int left, int right){ int i, j, temp, t; if (left > right) return; temp = arr[left]; i = left; j = right; while (i !=j) { //假设以左边的数为基准数,那么先移动的

2021-11-04 20:50:16 118

原创 STL的常用算法(2)

#include<iostream>using namespace std;#include<algorithm>#include<functional>#include<vector>#include<numeric>void print(int a){ cout << a<<" ";}//merge算法的实现void test1(){ vector<int>v1; vector&l

2021-10-27 11:44:32 76

原创 STL的常用算法(1)

STL的常用算法:#include<iostream>using namespace std;#include<vector>#include<algorithm>#include<functional>#include<ctime>void print(vector<int>& v){ for (vector<int>::iterator it = v.begin(); it != v.end()

2021-10-26 22:38:19 56

原创 C++之内建函数对象

下面我来讲解一下什么是函数对象,什么是一元谓词,二元谓词,同时也介绍一下STL提供的一些可以直接拿来使用的仿函数:#include<iostream>using namespace std;#include<vector>#include<algorithm>#include<functional>class base{public: base() { this->count = 0; } int operator()(int

2021-10-26 22:19:57 151

原创 STL之仿函数

仿函数,也可以称为函数对象,实则是一个类,重载了(),调用方便,十分灵活。#include<iostream>using namespace std;#include<vector>#include<algorithm>#include<functional>class base{public: base() { this->count = 0; } int operator()(int a,int b) { retur

2021-10-26 13:04:00 89

原创 STL之map容器的讲解(C++)

以下是对map容器的讲解:map容器有一个索引值,相当于位置,还有一个就是我们的真值,map容器和set容器一样会自动进行排列,底层也是二叉树。#include<iostream>using namespace std;#include<map>void print(map<int,int>&m){ for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {

2021-10-24 21:07:22 2710

原创 set容器的讲解(STL)(c++代码实现)

set容器很特殊,不允许重复插入,其底层为二叉树,且有自动排序的功能:#include<iostream>using namespace std;#include<set>void print(set<int>&s){ for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout <&

2021-10-24 18:05:43 316

原创 list容器讲解(STL,c++代码实现)

以下是笔者对STL之list的学习笔记:#include<iostream>using namespace std;#include<list>//list容器由于是不能随机访问的,所以没有at函数,不能通过[]去访问void print(const list<int>& v){ for (list<int>::const_iterator it = v.begin(); it != v.end(); it++) { cout &l

2021-10-24 12:12:48 101

原创 stack容器和queue容器的讲解(c++)

stack容器的主要成员函数有以下:#include<iostream>using namespace std;#include<stack>void test(){ stack<int>s; s.push(10);//栈的插入操作函数 s.push(20); s.push(30); s.push(40); s.emplace();//和push函数类似,但是参数可以不填,编译器默认填0 cout << "未出栈前的大小:" <&

2021-10-23 19:11:21 90

原创 deque容器的一些函数讲解(c++代码)

介绍一下deque容器的一些函数:#include<iostream>using namespace std;#include<deque>#include<algorithm>//如果不想被修改void print(const deque<int>&v){ //也可以通过at函数来获取数值, for (int i = 0; i < v.size(); i++) { cout << v.at(i) <&l

2021-10-22 22:10:31 183

原创 vector容器之reserve函数的讲解(c++)

下面来介绍一下reserve的作用,前面我们介绍了swap函数可以减少内存的浪费,reserve函数也有类似的作用:首先我们来看一下没有使用reserve函数前,我们的编译器需要开辟多少次,且容量的大小:#include<iostream>using namespace std;#include<vector>void print(vector<int>&v){ for (int i = 0; i < v.size(); i++) { c

2021-10-22 19:12:22 8334

原创 vector容器函数的简单讲解(尤其是对swap函数的讲解)(c++实现)

#include<iostream>using namespace std;#include<vector>void print(vector<int>&v){ for (vector<int>::iterator it=v.begin();it!=v.end();it++) { cout << *it << " "; } cout << endl;}void test(){ vector

2021-10-21 21:39:33 468

原创 关于string容器一些简单函数的讲解

一下来介绍一下string容器函数的用法:这里是一些增加和删除的函数#include<iostream>using namespace std;void test(){ string str = "I"; str += " LOVE LOL"; str.insert(5,4,'a');//c语言字符串,在第五个位置,插入四个a cout << "str1= " << str << endl;// str.insert(5, "aaa");/

2021-10-19 22:47:58 221

原创 模板实现选择排序(c++代码实现)

模板实现选择排序代码如下:#include<iostream>using namespace std;template<class T>void myswap(T &a,T &b){ T temp = a; a = b; b = temp;}template<class T>void sort(T arr[],int len){ for (int i = 0; i < len; i++) { int max = i;

2021-10-16 00:55:40 573

原创 c++复习之继承和多态

以上是c++面向对象的继承和多态的笔记,分享给大家。

2021-08-07 20:16:28 102 1

原创 c++复习计划之封装

以上是我c++面向对象关于封装的笔记,分享给大家。代码只有一遍遍敲才能理解,debug虽难,但是也在丰富自己学习的经验,加油,编程人!

2021-08-07 20:13:20 97

原创 引用在作为递增函数重载和左移运算符重载时做形参遇见的问题

代码如下:#include<iostream>using namespace std;#include<string>class father{friend void func();friend ostream& operator<<(ostream& cout, father f);public: father& operator++()//引用的本质在于返回自己本身,能够让后续的编程实现作用到自己 { M_age++;

2021-08-07 20:05:31 318 2

原创 当深拷贝和等号运算符重载相遇的问题

当深拷贝和等号运算符重载相遇的时候,我们可能在很多时候会混淆,话不多说,上代码:#include<iostream>using namespace std;class father{ public: father(int b) { M_a=new int(b); } //father(const father&b) //{ // // //M_a = b.M_a;//系统默认浅拷贝写法 // M_a = new int(*b.M_a);//深拷贝解决此类问

2021-08-06 18:59:34 120

原创 静态成员函数访问静态成员遇见的问题

下面来介绍一下静态成员函数和静态成员变量,以及遇到的问题,先看代码:#include<iostream>using namespace std;class father{public: static int M_a; int b; static void func() { M_a = 100;//静态成员函数可以访问静态成员变量 //b = 100;静态成员函数不可以访问非静态成员变量,无法区分到底是那个对象的 cout << "静态成员函数func的调

2021-08-04 19:31:22 364

原创 浅析深拷贝和浅拷贝

利用深拷贝的方法解决浅拷贝的问题,代码如下:#include<iostream>using namespace std;#include<string>class father{public: father() { cout << "father函数的无参构造函数" << endl; } father(int a, string name) { M_age = a; M_name = new string(name);//用指

2021-08-02 17:02:31 72

原创 虚析构和纯虚析构函数去解决子类开辟在堆区的空间释放不干净的问题

本篇文章讲解利用虚析构和纯虚析构函数去解决子类开辟在堆区的空间,释放子类开辟在堆区的空间,纯虚析构函数和虚析构的共同特点:必须要写实现,纯虚析构函数,类外写实现,虚析构函数类内写实现,都可以通过父类对象去释放子类开辟的空间(new出来的空间,开辟在堆区)1:代码如下:#include<iostream>#include<string>using namespace std;//抽象类class father{public: //纯虚函数 father() {

2021-08-01 17:56:27 226

原创 继承同名静态成员访问方式讲解(c++)

本文介绍静态成员访问的方式1:通过子类访问2:类名直接访问#include<iostream>using namespace std;class father{public: ~father() { cout << "父类析构函数调用。" << endl; } static int age; static void func() { cout << "父类函数func()的调用!" << endl; }

2021-07-30 18:01:25 106

原创 c++继承权限的讲解

#include<iostream>using namespace std;/*完成三种继承方式案例的举例和证明1:公共继承2:保护继承3:私有继承*///公共继承,先写父类class father{public: int age;protected: int mima;private: string mimi;};class son1 :public father{public: void func() { age = 100; mima

2021-07-29 17:20:36 225

原创 c++讲解成员对象作为函数参数传参的三种方式(主要是引用传递的讲解)

拿类对象作为函数参数举例,三种形式如下:#include<iostream>using namespace std;class cube{public: void setM_h(int h) { M_h = h; } int getM_h() { return M_h; } void setM_k(int k) { M_k = k; } int getM_k() { return M_k; } void setM_l(int l)

2021-07-27 18:05:10 1587

原创 c++学习笔记(暑期复习计划)

onenote记录的笔记,笔者可能还有很多不足,望大佬指正!后续还会有更新。

2021-07-24 10:42:04 221 4

空空如也

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

TA关注的人

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