![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 69
李小胖向前冲
这个作者很懒,什么都没留下…
展开
-
c++ 堆的vector实现
一、建堆 vector<int> nums = {9, 6, 2, 4, 7, 0, 1, 8, 3, 5}; 1、如果使用nums构建最大堆: make_heap(nums.begin(), nums.end()); //或 make_heap(nums.begin(), nums.end(), less<int>()); 9 8 2 6 7 0 1 4 3 5 2.构建最小堆 make_heap(nums.begin(),nums.end(),greater转载 2021-04-26 14:19:09 · 603 阅读 · 0 评论 -
c++ string类
c也有string关键字,但是作用很有限,因为它只能表示字符串常量。 c++中 string 功能就强大许多,完全可以代替字符数组的作用。 1.使用string需要加入头文件<string> 2.下面的例子介绍了几种定义 string 变量(对象)的方法: #include <iostream> #include <string> using namespace std; int main(){ string s1;//只是定义但并未初始化 s原创 2021-04-10 10:43:28 · 300 阅读 · 0 评论 -
c++之复制构造函数
它只有一个参数,参数类型是本类的引用。参数可以是const引用,也可以是非const引用。建议是const引用,为什么? 因为这样可以让对象是常量对象作为参数,也可以让非常量对象作为参数 。 如果你自己不写复制构造函数,系统会自动创建一个 下面是默认复制构造函数的一个例子: #include<iostream > using namespace std; class Complex { public: double real, imag; Complex(double转载 2021-04-09 17:06:15 · 138 阅读 · 0 评论