1.C++ class 类的用法,什么时候用this->

this 是 C++ 中的一个关键字,也是一个 const 指针,它指向当前对象,通过它可以访问当前对象的所有成员。

所谓当前对象,是指正在使用的对象。例如对于stu.show();,stu 就是当前对象,this 就指向 stu。

下面例子是因为重名所以用this 不重名变量可以直接赋值,详见下下个代码

class MovingAverage {
public:
    MovingAverage(int size) {
        this->size = size;
        sum = 0;
    }
    
    double next(int val) {
        if (q.size() >= size) {
            sum -= q.front(); q.pop();
        }
        q.push(val);
        sum += val;
        return sum / q.size();
    }
    
private:
    queue<int> q;
    int size;
    double sum;
};
#include<bits/stdc++.h>
using namespace std;
class MovingAverage {
public:
    MovingAverage(int size) {
        size1 = size;
        sum = 0;
    }

    double next(int val) {
        if (q.size() >= size1) {
            sum -= q.front(); q.pop();
        }
        q.push(val);
        sum += val;
        return sum / q.size();
    }

private:
    queue<int> q;
    int size1;
    double sum;
};
int main()
{
    int size=3;
    MovingAverage* ma=new MovingAverage(size);
    int a=ma->next(4),b=ma->next(6),c=ma->next(3),d=ma->next(2);
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    return 0;
}

 

 

 

2.红黑树 c++ const static区别

树和图的题 BFS/DFS DP 有向无向 拓扑排序

3.C++ 虚函数 纯虚函数 友元类 模板类

4.计网和计组

5.统计学习方法,找视频

6.机器学习 深度学习 神经网络 迁移学习

 7.multiset好的总结

https://blog.csdn.net/longshengguoji/article/details/8546286

#include <iostream>
#include <set>

using namespace std;

int main ()
{
    int myints[]={12,75,10,32,20,25};
    //用数组初始化,但是赋给set内部直接排序了
    set<int> first (myints,myints+3);     // 10,12,75
    set<int> second (myints+3,myints+6);  // 20,25,32

    //swap函数用法,交换两个set的值
    first.swap(second);

    cout << "first contains:";
    for (set<int>::iterator it=first.begin(); it!=first.end(); ++it)
        cout << ' ' << *it;
    cout << '\n';

    cout << "second contains:";
    for (set<int>::iterator it=second.begin(); it!=second.end(); ++it)
        cout << ' ' << *it;
    cout << '\n';

    return 0;
}

 

8.unordered_map用法

equal_range用法不知道

 

 

 

 

 

 

 

posted on 2020-02-17 13:55  黑暗尽头的超音速炬火  阅读(127)  评论(0)    收藏  举报