09 2021 档案
摘要:**算法简介:** - `set_intersection` // 求两个容器的交集 - `set_union` // 求两个容器的并集 - `set_difference ` // 求两个容器的差集 #### 5.6.1 set_intersection **功能描述:** * 求两个容器的交
阅读全文
摘要:**算法简介:** - `copy` // 容器内指定范围的元素拷贝到另一容器中 - `replace` // 将容器内指定范围的旧元素修改为新元素 - `replace_if ` // 容器内指定范围满足条件的元素替换为新元素 - `swap` // 互换两个容器的元素 #### 5.4.1 co
阅读全文
摘要:**算法简介:** - `sort` //对容器内元素进行排序 - `random_shuffle` //洗牌 指定范围内的元素随机调整次序 - `merge ` // 容器元素合并,并存储到另一容器中 - `reverse` // 反转指定范围的元素 #### 5.3.1 sort **功能描述:
阅读全文
摘要:#include<iostream> using namespace std; #include<algorithm> #include<vector> void print01(int val) { cout << val << ""; } class print02 { public: void
阅读全文
摘要:## 4 STL- 函数对象### 4.1 函数对象#### 4.1.1 函数对象概念**概念:*** 重载**函数调用操作符**的类,其对象常称为**函数对象*** **函数对象**使用重载的()时,行为类似函数调用,也叫**仿函数****本质:**函数对象(仿函数)是一个**类**,不是一个函数
阅读全文
摘要:### 3.9 map/ multimap容器#### 3.9.1 map基本概念**简介:*** map中所有元素都是pair* pair中第一个元素为key(键值),起到索引作用,第二个元素为value(实值)* 所有元素都会根据元素的键值自动排序**本质:*** map/multimap属于*
阅读全文
摘要:#include <set> void printSet(set<int> & s) { for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } //构造
阅读全文
摘要:#include <list> void printList(const list<int>& L) { for (list<int>::const_iterator it = L.begin(); it != L.end(); it++) { cout << *it << " "; } cout
阅读全文
摘要:#include <queue> #include <string> class Person { public: Person(string name, int age) { this->m_Name = name; this->m_Age = age; } string m_Name; int
阅读全文
摘要:#include <stack> //栈容器常用接口 void test01() { //创建栈容器 栈容器必须符合先进后出 stack<int> s; //向栈中添加元素,叫做 压栈 入栈 s.push(10); s.push(20); s.push(30); while (!s.empty())
阅读全文
摘要:#include <deque> void printDeque(const deque<int>& d) { for (deque<int>::const_iterator it = d.begin(); it != d.end(); it++) { cout << *it << " "; } c
阅读全文
摘要:```C++ #include <vector> void printVector(vector<int>& v) { for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; } co
阅读全文
摘要:#include<iostream> using namespace std; #include<string> //string的构造函数 // //* `string(); ` //创建一个空的字符串 例如: string str; //`string(const char* s); ` //使
阅读全文
摘要:## 2 STL初识### 2.1 STL的诞生* 长久以来,软件界一直希望建立一种可重复利用的东西* C++的**面向对象**和**泛型编程**思想,目的就是**复用性的提升*** 大多情况下,数据结构和算法都未能有一套标准,导致被迫从事大量重复工作* 为了建立数据结构和算法的一套标准,诞生了**
阅读全文
摘要:```C++ //交换整型函数 void swapInt(int& a, int& b) { int temp = a; a = b; b = temp; } //交换浮点型函数 void swapDouble(double& a, double& b) { double temp = a; a =
阅读全文
摘要:class Animal { public: //Speak函数就是虚函数 //函数前面加上virtual关键字,变成虚函数,那么编译器在编译的时候就不能确定函数调用了。 virtual void speak() { cout << "动物在说话" << endl; } }; class Cat :
阅读全文
摘要:#include<iostream> using namespace std; //普通实现页面 //Java 页面 class Java { public: void header() { cout << "首页、公开课、登录、注册>>>>(公共头部)" << endl; } void foote
阅读全文
摘要:加号运算符重载 运算符重载的本质是 //成员函数重载本质调用Person p3 = p1.operator+(p2);Person p3 = p1 +p2;//全局函数重载本质调用 Person p3 = operator+(p1,p2);//需注意 运算符重载 也可以发生函数重载Person p3
阅读全文
摘要:#include <iostream> using namespace std; #include<string> //全局函数做友元 class Building{ //goodGay 全局函数是Building好朋友,可以访问Building中私有成员 friend void goodGay(B
阅读全文
摘要:#include <iostream> using namespace std; class Person { int m_A;//非静态成员变量 属于类的对象上的 static int m_B;//静态成员变量 不属于类的对象上 void func(){}//非静态成员函数 static void
阅读全文
摘要:#include <iostream> using namespace std; #include <string> //对象的初始化和清理 //1、构造函数 进行初始化操作 class Person { public: //1.1 构造函数 //没有返回值 不同写void //函数名 与类名相同
阅读全文
摘要:#include <iostream> using namespace std; //定义一个圆类 求得圆的周长 //求圆周长的公式为 2*PI*半径 const double PI = 3.14; class Circle { //访问权限 //公共访问权限 public: //属性 int m_
阅读全文
摘要:#include <iostream> using namespace std; #include <fstream> //读文件的操作函数 void read() { //1、包含读写文件的头文件 #include <fostream> //2、创建读文件的对象 ofstream fos; //3
阅读全文
摘要:函数的默认参数 函数的占位参数 返回值 函数名 (数据类型){} 函数重载 函数重载的注意事项
阅读全文
摘要:int main 引用 引用做函数的参数//交换函数//1、值传递void mySwap01(int a ,int b){ int temp = a; a = b; b = temp; cout <<"Swap01 a="<<a<<endl; cout <<" Swap01 b="<<b<<endl
阅读全文
摘要:intmain内存分区模型代码区:存放函数的二进制代码,有操作系统进行管理的全局区:存放全局变量和静态变量以及常量栈区:由编译器自动分配与释放,存放函数的参数值,局部变量等堆区:由程序员分配和释放,若程序员不释放,则在程序接收的时候由操作系统回收 内存机制: c++ 中在程序运行前分为全局区和代码区
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/middle-of-the-linked-list/ 题目说明: 给定一个头结点为 head 的非空单链表,返回链表的中间结点。 如果有两个中间结点,则返回第二个中间结点。 示例 1:输入:[1,2,3,4,5]输出:此列表
阅读全文
摘要:结构体也就是一种用户可以自定义的数据类型 例如: // 创建学生的数据类型,:学生包括(姓名,年龄,分数) struct Student { string name; int age; intscore; } 2、通过学生类型创建具体学生(前提是已经创建了学生这个数据类型) 2.1 struct S
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/combination-sum-ii/ 题目说明: 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的每个数字
阅读全文
摘要:作用:让代码结构更加的清晰 函数分文件编写一般有4个步骤 1.创建后缀为.h的头文件 2.创建后缀为.cpp的源文件 3.在头文件中写函数的声明 4.在源文件中写函数的定义 1.注释 ctrl+k, ctrl+c 2.取消注释 ctrl+k,ctrl+u 指针: 使用指针 可以通过解引用的方式来找到
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/combination-sum/ 题目说明: 给定一个无重复元素的正整数数组 candidates 和一个正整数 target ,找出 candidates 中所有可以使数字和为目标数 target 的唯一组合。candid
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/ 题目说明: 给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点,返回 null 。图示两个链
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/linked-list-cycle/ 题目说明: 给定一个链表,判断链表中是否有环。如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/valid-parentheses/ 题目说明: 给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/pascals-triangle-ii/ 题目说明: 给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行。 在「杨辉三角」中,每个数是它左上方和右上方的数的和。 示例 1:输入: rowIndex
阅读全文
浙公网安备 33010602011771号