STL中的常用算法详解

这篇具有很好参考价值的文章主要介绍了STL中的常用算法详解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1. STL常用算法

STL的算法主要是由下面的头文件组成的。

 <algorithm>  <functional> <numeric>

1.algorithm是所有STL头文件中最大的一个范围涉及到比较、交换、查找、遍历操作、复制、修改等等算法的头文件。

2.numeric体积很小,只包括几个再序列上面进行简单数学运算的模板函数。

3.functional定义了一些模板类,用以声明函数对象。

4.如果读者还未知晓什么是仿函数,建议了解一下。

link:[https://blog.csdn.net/toby54king/article/details/105103111]

2. algorithm中常用的算法

2.1 STL常用遍历算法

for_each   //遍历容器

transform  //搬运容器中的元素到另一个容器

2.1.1 for_each函数

//遍历容器

//函数原型
for_each(iterator beg,iterator end,fund);
//遍历容器中的元素

//beg  开始迭代器

//end  结束迭起器

//_func 函数或仿函数,通过该参数对遍历的元素进行对应的操作

2.1.2 for_each案例:

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

//函数
void print1(int val)
{
    cout<<val<<" ";
}

//仿函数
class print2
{
    public:
    void operator()(int val)
    {
        cout<<val<<" ";
    }
};

int main()
{
    vector<int>arr={1,2,3,4,5,6,7,8};

    //函数传参
    for_each(arr.begin(),arr.end(),print1);

    cout<<endl;

    //仿函数传参
    for_each(arr.begin(),arr.end(),print2());

    //要注意的是,for_each的参数之间是逗号,并非分号。
    //最后的参数如果是函数,传参时不需要扩号,如果是仿函数,则需要扩号。
    return 0;
}

2.1.3 transform函数

//将容器内的元素搬运到另外一个容器中。

//函数原型
tranform(iterator beg1, iterator end1, iterator beg2, _fund);

//  beg1 源容器的开始迭代器

//  end1 源容器的结束迭代器

//  beg2 目标容器的开始迭代器

//  _func函数或者仿函数,通过该参数,可以对源容器中的元素进行相应的 操作

2.1.4 transform案例

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

//函数
int Transform1(int val)
{
    return val+100;
}

//仿函数
class Transform2
{
    public:
    int operator()(int val)
    {
        return val+100;
    }
};

void print(vector<int> arr)
{
    for(auto i=arr.begin();i!=arr.end();i++)
    {
        cout<<*i<<" ";
    }
    cout<<endl;
}

int main()
{
    vector<int>arr1={1,2,3,4,5,6,7,8};
    vector<int>arr2={12,13,14,15,16};
    print(arr1);
    cout<<endl;

    //函数传参
    transform(arr1.begin(),arr1.end(),arr2.begin(),Transform1);
    print(arr1);
    print(arr2);

    cout<<endl;
    cout<<endl;

    //仿函数传参
    transform(arr1.begin(), arr1.end(), arr2.begin()+3, Transform2());
    print(arr1);
    print(arr2);

    //要注意的是,transform的参数之间是逗号,并非分号。
    //最后的参数如果是函数,传参时不需要扩号,如果是仿函数,则需要扩号。


    //结果为:
//1 2 3 4 5 6 7 8

//1 2 3 4 5 6 7 8
//101 102 103 104 105


//1 2 3 4 5 6 7 8
//101 102 103 101 102
    return 0;
}


从该结果可以看出,
transform函数搬运完成后,并不会对源容器产生影响。当目标容器在搬运区间内有元素时,原来的元素值会被覆盖,搬运只会在目标容器已有的空间进行,并不会开辟新的空间,当迭代器来到目标容器的end迭代器时,搬运就会结束。

2.2 STL常用的查找算法

find  //查找元素

find_if  // 按条件查找元素

adjacent_find   // 查找相邻元素

binary_search   //二分查找

cout   //统计元素个数

cout_if   //按条件统计元素个数

2.2.1 find函数


// 查找指定元素,返回找到元素的迭代器或end迭代器。

//函数原型
find(iterator beg, iterator end, value);

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

// value 查找的元素

2.2.2 find案例

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    vector<int>arr={1,4,2,3,5,7,7,8};
    auto it=find(arr.begin(),arr.end(),5);
    if(it == arr.end())
    {
        cout<<"没有该元素"<<endl;
    }
    else
    {
        cout<<*it<<endl;
    }

    return 0;
}

// 该函数和部分容器内的find函数重名,但要注意的是,两者并不相同
// 前者只能应用于对应容器,后者可以所有容器使用。

2.2.3 find_if 函数

//按条件查找元素

//函数原型
find_if(iterator beg,iterator end, _Pred);

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

// _Pred 函数或谓词(返回bool类型的仿函数)

2.2.4 find_if 案例

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Find1 {
public:
    bool operator()(int val)
    {
        return val > 3;
    }
};

bool Find2(int val)
{
    return val > 5;
}

int main()
{
    vector<int>arr = { 1,2,3,4,5,6,7,8 };
    auto it = find_if(arr.begin(), arr.end(), Find2);
    if (it == arr.end())
    {
        cout << "没有该元素" << endl;
    }
    else
    {
        cout << *it << endl;
    }

    cout << endl;

    auto it1 = find_if(arr.begin(), arr.end(), Find1());
    if (it1 == arr.end())
    {
        cout << "没有该元素" << endl;
    }
    else
    {
        cout << *it1 << endl;
    }
    return 0;
}

2.2.5 adjacent_find 函数


//查找相邻元素


//函数原型
adjacent_find(iterator beg,iterator end);

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

2.2.6 adjacent_find 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    vector<int>arr={1,2,2,3,3,4,5,6,7,8};
    auto it=adjacent_find(arr.begin(),arr.end());
    if(it == arr.end())
    {
        cout<<"没有该元素"<<endl;
    }
    else
    {
        cout<<*it<<endl;
    }
//显然,adjacent_find函数只会找到第一组相邻重复的元素
    return 0;
}

2.2.7 binary_search 函数


//查找指定元素是否存在
//要求查找序列为有序
//速度相对普通查找较快

//函数原型
bool binary_search(iterator beg, iterator end, value);

//跟find 相比,只会返回true或false

//且要求有序序列

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

// value 查找的元素

2.2.8 binary_search 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    vector<int>arr={1,2,3,4,5,6,7,8};
    auto it=binary_search(arr.begin(),arr.end(),5);
    if(!it)
    {
        cout<<"没有该元素"<<endl;
    }
    else
    {
        cout<<"存在该元素"<<endl;
    }

//要注意的是,binary_search只能查找有序序列
    return 0;
}

2.3 STL 的计数算法


cout   //统计元素个数

cout_if //按条件统计元素个数

2.3.1 count 函数

//统计元素个数

//函数原型
count(iterator beg, iterator end, value);

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

// value 统计的元素

// 通过返回值来接收统计的元素个数

2.3.2 cout_if 函数


//按条件统计元素个数

//函数原型
cout_if(iterator beg, iterator end, _Pred);

//  beg 源容器的开始迭代器

//  end 源容器的结束迭代器

// _pred 函数或谓词

2.3.3 count和count_if案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class count1{
    public:
    bool operator()(int val)
    {
        return val>4;
    }
};

bool count2(int val)
{
    return val>3;
}

int main()
{
    vector<int>arr={1,2,9,2,5,3,11,7,4,6};
    auto it=count(arr.begin(),arr.end(),2);
    cout<<it<<endl<<endl;

    auto it1=count_if(arr.begin(), arr.end(), count1());
    cout<<it1<<endl<<endl;
    
    int it2=count_if(arr.begin(),arr.end(), count2);

    cout<<it2<<endl<<endl;

    return 0;
}

2.4 STL 常用的排序算法


sort //对容器内的元素进行排序

random_shuffle  //洗mergee牌  指定范围内的元素进行随机调整

merge //合并两个容器,存储在另外一个容器内

reverse //反转指定范围内的元素

2.4.1 sort 函数


//对容器内的元素进行排序

//函数原型
sort(iterator beg, iterator end, _Pred);

//beg  开始迭代器

//end  结束迭代器

//_Pred  函数或谓词

2.4.2 sort 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Grater{
    public:
    bool operator()(int v1,int v2)
    {
        return v1<v2;
    }
};

bool Grater1(int val1,int val2)
{
    return val1<val2;
}

void Print(int val)
{
    cout<<val<<" ";
}

int main()
{
    vector<int>arr={12,22,29,34,5,13,21,17,14,6};
    vector<int>arr1={33,45,11,0,4,3,22,67,94,16};
    for_each(arr.begin(),arr.end(),Print);
    cout<<endl;
    for_each(arr1.begin(),arr1.end(),Print);


    cout<<endl<<endl;
    sort(arr.begin(),arr.end(),Grater1);
    for_each(arr.begin(),arr.end(),Print);
    
    cout<<endl<<endl;
    sort(arr1.begin(),arr1.end(),Grater());
    for_each(arr1.begin(),arr1.end(),Print);

    return 0;
}

2.4.3 random_shuffle 函数


//洗牌   指定范围内的元素随机调整

//函数原型
random_shuffle(iterator beg,  iterator end);

//beg  开始迭代器

//end  结束迭代器

2.4.4 random_shuffle 案例


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<ctime>

using namespace std;

class Print{
    public:
    void operator()(int val)
    {
        cout<<val<<" ";
    }
};

int main()
{
    vector<int>arr={1,2,6,7,8,12,13,17,24,36};
    srand((unsigned int)time(NULL));  
   //使用random_shuffle函数时,跟使用random一样,一定要设置随机种子。
    for_each(arr.begin(),arr.end(),Print());

    cout<<endl;

    random_shuffle(arr.begin(),arr.end());
    for_each(arr.begin(),arr.end(),Print());

    cout<<endl;
    
    return 0;
}

2.4.5 merge 函数


//两个容器元素合并,存储在另外一个容器

//函数原型
merge(iterator beg1, iterator end1, iterator beg2, iterator end2,  iterator dest);

//注意,两个容器必须是有序的

//  beg1 容器1的开始迭代器

//  end1 容器1的结束迭代器

//  beg2 容器2的开始迭代器

//  end2 容器2的结束迭代器

//dest 目标容器的开始迭代器

// 目标容器必须要提前分配足够大的空间

2.4.6 merge 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Print{
    public:
    void operator()(int val)
    {
        cout<<val<<" ";
    }
};

int main()
{
    vector<int>arr={1,2,4,5,8,9,11,21,33,45};
    vector<int>arr1={2,5,8,10,12,17,23,66};

    vector<int>arr2;
    arr2.resize(arr.size()+arr1.size());
    for_each(arr2.begin(),arr2.end(),Print());
    cout<<endl;

    merge(arr.begin(),arr.end(),arr1.begin(),arr1.end(),arr2.begin());

    for_each(arr2.begin(),arr2.end(),Print());

    //两个源容器必须是有序的

    //目标容器必须要提前分配好足够大的空间

    //合并后的目标容器仍然是有序的

    cout<<endl;

    return 0;
}

reverse 函数


//将容器内元素进行反转

//函数原型
reverse(iterator beg, iterator end);

//beg 开始迭代器

//end 结束迭代器

2.4.7 reverse 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Print{
    public:
    void operator()(int val)
    {
        cout<<val<<" ";
    }
};

int main()
{
    vector<int>arr={1,2,4,5,8,9,11,21,33,45};
    vector<int>arr1={12,5,82,120,42,17,73,66};

    for_each(arr.begin(),arr.end(),Print());
    cout<<endl<<endl;
    for_each(arr1.begin(),arr1.end(),Print());
     cout<<endl<<endl;

    reverse(arr.begin(),arr.end());
    reverse(arr1.begin(),arr1.end());

    for_each(arr.begin(),arr.end(),Print());
     cout<<endl<<endl;
    for_each(arr1.begin(),arr1.end(),Print());
    cout<<endl<<endl;

    return 0;
}

2.5 STL常用的拷贝和替换函数

copy   //将容器内指定的范围拷贝到另外一个容器内

copy_if  //将容器内指定范围满足条件的元素拷贝到另外一个容器内

replace // 将容器指定的范围的旧元素修改为新元素

repalce_if // 容器内指定范围满足条件的元素替换成新元素

swap   //交换两个容器的元素

2.5.1 copy 函数

//将容器内指定的范围拷贝到另外一个容器内

//函数原型
copy(iterator beg, iterator end, iterator dest);

//beg 开始迭代器

//end 结束迭代器

//dest 目标开始拷贝的迭代器

2.5.2 copy_if 函数


//将容器内指定范围满足条件的元素拷贝到另外一个容器内

//函数原型
copy(iterator beg, iterator end, iterator dest, _Pred);

//beg 开始迭代器

//end 结束迭代器

//dest 目标开始拷贝的迭代器

//_pred 函数或谓词

2.5.3 copy 和 copy_ if 案例


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

bool Graver(int val)
{
    return val > 3;
}

class Graver1 {
public:
    bool operator()(int val)
    {
        return val < 3;
    }
};

int main()
{
    vector<int>arr = { 1,2,4,5,8,9,11,21,33,45 };
    vector<int>arr1 = { 12,5,82,9 };
    arr1.resize(arr.size());

    copy(arr.begin(), arr.end(), arr1.begin());
    for_each(arr1.begin(), arr1.end(), Print());
    cout << endl << endl;
    //结果 1 2 4

    //这里的结果可以看出copy同上面的merge一样,需要开辟足够
  
    //且拷贝的值会覆盖原来的容器内的值。

    vector<int>arr3 = { 1,2,4,5,8,9,11,21,33,45 };
    vector<int>arr4 = { 12,5,82,9 };
    arr4.resize(arr3.size());
    copy_if(arr3.begin(), arr3.end(), arr4.begin(), Graver1());
    for_each(arr4.begin(), arr4.end(), Print());
    cout << endl << endl;

    vector<int>arr5 = { 1,2,4,5,8,9,11,21,33,45 };
    vector<int>arr6 = { 12,5,82,9 };
    arr6.resize(arr5.size());

    copy_if(arr5.begin(), arr5.end(), arr6.begin(), Graver);
    for_each(arr6.begin(), arr6.end(), Print());
    cout << endl << endl;
    return 0;
}

2.5.4 replace 函数

//将指定容器内范围的旧元素替换成新元素

//函数原型
replace(iterator beg, iterator end, oldvalue, newvalue);

//beg 开始迭代器

//end 结束迭代器

//oldvalue 旧元素

//newvalue 新元素

2.5.6 replace_if 函数

//将区间内满足条件的元素替换成指定元素

//函数原型

replace_if (iterator beg, iterator end, _pred, newvalue);

//beg 开始迭代器

//end 结束迭代器

//_Pred 函数或谓词

//newvalue 新元素

2.5.7 replace 和 replace_if 案例

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Print{
    public:
    void operator()(int val)
    {
        cout<<val<<" ";
    }
};

class change{
    public:
    bool operator()(int val)
    {
        return val<20;
    }
};

int main()
{
    vector<int>arr={1,1,4,5,8,9,1,1,33,1};
    vector<int>arr1={12,5,82,120,42,17,73,66};

    for_each(arr.begin(),arr.end(),Print());
    cout<<endl;
    for_each(arr1.begin(),arr1.end(),Print());
    cout<<endl;

    replace(arr.begin(),arr.end(),1,10);
    replace_if(arr1.begin(),arr1.end(),change(),10);

    for_each(arr.begin(),arr.end(),Print());
    cout<<endl;
    for_each(arr1.begin(),arr1.end(),Print());
    cout<<endl;


    return 0;
}

2.5.8 swap 函数

//交换两个容器内的元素

//函数原型
swap(container c1, container c2);

// c1 容器1

// c2 容器2

2.5.9 swap 案例

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

int main()
{
    vector<int>arr = { 1,1,4,5,8,9,1,1,33,1 };
    vector<int>arr1;

    for_each(arr.begin(), arr.end(), Print());
    cout << endl;
    for_each(arr1.begin(), arr1.end(), Print());
    cout << endl;

    swap(arr, arr1);
    for_each(arr.begin(), arr.end(), Print());
    cout << endl;
    for_each(arr1.begin(), arr1.end(), Print());
    cout << endl;
    
//swap函数并没有要求交换的两个容器有足够大的空间,它会自动调整两个容器的空间大小。
    
    return 0;
}

2.6 STL 的常用集合算法


set_intersection  //求两个容器的交集

set_union    //  求两个容器的并集

set_difference  // 求两个容器的差集

2.6.1 set_intersection 函数


//求两个容器的并集

//函数原型
set_intersection(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

//  beg1 容器1的开始迭代器

//  end1 容器1的结束迭代器

//  beg2 容器2的开始迭代器

//  end2 容器2的结束迭代器

// dest 目标容器的开始迭代器

// 两个源容器必须时升序

// 目标容器必须要有足够大的空间

// 返回最后一个交集元素的下一个位置

2.6.2 intersecton 案例

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

int main()
{
    vector<int>arr = { 1,2,4,5,8,9,45,17,33,10 };
    vector<int>arr1 = { 33,5,2,10,42,17,73,66 };

    sort(arr.begin(), arr.end());

    sort(arr1.begin(), arr1.end());

    //这里要记住,两个源容器必须时有序的

    vector<int>arr2;
    arr2.resize(min(arr.size(), arr1.size()));

    auto post =set_intersection(arr.begin(), arr.end(), arr1.begin(), arr1.end(), arr2.begin());

    for_each(arr2.begin(), arr2.end(), Print());
    cout << endl;
    //因为交集并不一定跟预设的空间大小一样大,所以打印的时候,我们会用set_intersection的返回值作为参数
    for_each(arr2.begin(), post, Print());
    return 0;
}

注意事项:

求交集的两个集合必须是有序序列

目标容器开辟空间需要从两个容器中去小值

set_intersection返回值即是交集中最后一个元素的下一个位置文章来源地址https://www.toymoban.com/news/detail-610740.html

2.6.3 set_union 函数

//  求两个集合的并集

// 函数原型
set_union(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

//  beg1 容器1的开始迭代器

//  end1 容器1的结束迭代器

//  beg2 容器2的开始迭代器

//  end2 容器2的结束迭代器

// dest 目标容器的开始迭代器

// 两个源容器必须时升序

// 目标容器必须要有足够大的空间

// 返回最后一个并集元素的下一个位置


2.6.4 set_union 案例


#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

int main()
{
    vector<int>arr = { 1,2,4,5,8,9,45,17,33,10 };
    vector<int>arr1 = { 33,5,2,10,42,17,73,66 };

    sort(arr.begin(), arr.end());

    sort(arr1.begin(), arr1.end());

    //这里要记住,两个源容器必须时有序的

    vector<int>arr2;
    arr2.resize(arr.size() + arr1.size());

    auto post =set_union(arr.begin(), arr.end(), arr1.begin(), arr1.end(), arr2.begin());

    cout << *post << endl;
    //返回值的位置

    for_each(arr2.begin(), arr2.end(), Print());
    cout << endl;

    //因为并集自动去重,并不一定跟预设的空间大小一样大,所以打印的时候,我们会用set_union的返回值作为参数
    for_each(arr2.begin(), post, Print());

	//结果:
    //0
	//1 2 4 5 8 9 10 17 33 42 45 66 73 0 0 0 0 0
	//1 2 4 5 8 9 10 17 33 42 45 66 73
    return 0;
}



2.6.5 set_difference 函数

//求两个集合的差集

// 函数原型
set_difference(iterator beg1, iterator end1, iterator beg2, iterator end2, iterator dest);

//  beg1 容器1的开始迭代器

//  end1 容器1的结束迭代器

//  beg2 容器2的开始迭代器

//  end2 容器2的结束迭代器

// dest 目标容器的开始迭代器

// 两个源容器必须时升序

// 目标容器必须要有足够大的空间

// 返回最后一个差集元素的下一个位置

2.6.6 set_difference 案例


#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

int main()
{
    vector<int>arr = { 1,2,4,5,8,9,45,17,33,10 };
    vector<int>arr1 = { 33,5,2,10,42,17,73,66 };

    sort(arr.begin(), arr.end());

    sort(arr1.begin(), arr1.end());

    //这里要记住,两个源容器必须时有序的

    vector<int>arr2;
    arr2.resize(max(arr.size(),arr1.size()));

    auto post =set_difference(arr.begin(), arr.end(), arr1.begin(), arr1.end(), arr2.begin());

    for_each(arr2.begin(), post, Print());
    cout << endl;

    auto post1 = set_difference(arr1.begin(), arr1.end(), arr.begin(), arr.end(), arr2.begin());

    for_each(arr2.begin(), post1, Print());
    cout << endl;
    //因为差集并不一定跟预设的空间大小一样大,所以打印的时候,我们会用set_difference的返回值作为参数
    //传参的时候,两个容器的先后顺序不一样,结果也不一样。
    return 0;
}


3. numeric 中常用的算法

3.1 STL 的常用算术生成算法


accumulate //计算容器元素累计总和

fill       // 向容器中添加元素

3.1.1 accumulate 函数

//  计算区间内容器元素累计总和

//  函数原型:
accumalate(iterator beg, iterator end, value);

// beg  开始迭代器

// end  结束迭代器

// value 起始值

3.1.2 fill 函数

//向容器内中填充指定元素

//函数原型
fill(iterator beg, iterator end, value);

// beg  开始迭代器

// end  结束迭代器

// value 填充值

3.1.3 accumulate 和 fill 案例

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

class Print {
public:
    void operator()(int val)
    {
        cout << val << " ";
    }
};

int main()
{
    vector<int>arr = { 1,1,4,5,8,9,1,1,33,1 };
    vector<int>arr1 = { 12,5,82,120,42,17,73,66 };

    cout << accumulate(arr.begin(), arr.end(), 5) << endl << endl;

    fill(arr1.begin(), arr1.end(), 5);
    for_each(arr1.begin(), arr1.end(), Print());

    //结果为:
    // 69

    //5 5 5 5 5 5 5 
    
    //可以看到,在fill的填充范围内,容器内原来的值会被覆盖
    return 0;
}

到了这里,关于STL中的常用算法详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 第九层(16):STL终章——常用集合算法

    🎉welcome🎉 ✒️博主介绍:一名大一的智能制造专业学生,在学习C/C++的路上会越走越远,后面不定期更新有关C/C++语法,数据结构,算法,Linux,ue5使用,制作游戏的心得,和大家一起共同成长。 ✈️C++专栏:C++爬塔日记 😘博客制作不易,👍点赞+⭐收藏+➕关注 在上一块

    2024年02月02日
    浏览(25)
  • C++系列二:STL教程-常用算法

    提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 还有一些我在尝试中迷惑不解的,有点玄幻。 排序算法: 合并算法: 查找算法: 筛选分组算法: 其他:

    2024年02月13日
    浏览(35)
  • Day 31 C++ STL常用算法(下)

    copy——容器内指定范围的元素拷贝到另一容器中 函数原型 copy(iterator beg, iterator end, iterator dest); // 按值查找元素,找到返回指定位置迭代器,找不到返回结束迭代器位置 // beg 开始迭代器 // end 结束迭代器 // dest 目标起始迭代器 注意——利用copy算法在拷贝时,目标容器要提前

    2024年02月12日
    浏览(31)
  • 机器学习笔记之最优化理论与方法(七)无约束优化问题——常用求解方法(上)

    本节将介绍 无约束优化问题 的常用求解方法,包括 坐标轴交替下降法、最速下降法 。 本节是对优化算法(十~十七)最速下降法(梯度下降法)的理论补充,其中可能出现一些定理的 证明过程 这里不再赘述,并在相应位置 附加链接 。 从本节开始,将介绍 四大类 无约束优化问

    2024年02月10日
    浏览(38)
  • 机器学习笔记之最优化理论与方法(九)无约束优化问题——常用求解方法(下)

    上一节介绍了 牛顿法、拟牛顿法 。本节将继续以 拟牛顿法 为基础,介绍 DFP , BFGS text{DFP},text{BFGS} DFP , BFGS 方法 。 经典牛顿法缺陷与修正牛顿法 关于 经典牛顿法 中关于 下降方向 D k ( k = 1 , 2 , ⋯   , ∞ ) mathcal D_k(k=1,2,cdots,infty) D k ​ ( k = 1 , 2 , ⋯ , ∞ ) 的 数学符号 表

    2024年02月09日
    浏览(42)
  • String类的学习笔记(上):介绍String类及其常用方法的使用

    本文介绍了Java中用来描述操作字符串的String类,和其一些常用的基本操作方法,字符串的创建输出,字符串对象的比较,字符串查找,字符串的转化,字符串的替换,字符串拆分,字符串截取,和大小写转换,去除左右空格,子字符串包含,学会使用这些方法,能更方便的使用操作字符串~ 前言

    2023年04月23日
    浏览(44)
  • 【学习笔记】unity脚本学习(五)【常用的方法函数Destroy、Instantiate 、SendMessage、invoke 、Coroutine】

    转载请注明出处:🔗https://blog.csdn.net/weixin_44013533/article/details/130233098 视频参考 极客学院Unity3D视频精讲课程 Object体系结构 可以看到MonoBehaviour继承自Component,Component继承自Object MonoBehaviour复习 MonoBehaviour官网API 之前学的start awake等都是Message事件响应函数,它们都是我们在脚本

    2024年02月04日
    浏览(34)
  • C++STL——list容器及其常用操作(详解)

    纵有疾风起,人生不言弃。本文篇幅较长,如有错误请不吝赐教,感谢支持。 链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。 链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态

    2024年02月14日
    浏览(29)
  • 【STL切片算法文献笔记】一种使用 STL 文件进行高效轮廓构造的改进切片算法

    STL 模型是通过将实体模型曲面细分为三角形而获得的。 镶嵌的精度由弦误差控制,弦误差是镶嵌模型与原始实体模型之间的最大形状差异。 细分实体模型所需的三角形数量是可接受的弦误差和零件几何复杂性的函数。 在 STL 文件创建过程中生成的大量三角形可能会影响对模

    2023年04月09日
    浏览(25)
  • 【生态经济学】R语言机器学习方法在生态经济学领域中的实践技术

    查看原文基于R语言机器学习方法在生态经济学领域中的实践技术 近年来,人工智能领域已经取得突破性进展,对经济社会各个领域都产生了重大影响,结合了统计学、数据科学和计算机科学的机器学习是人工智能的主流方向之一,目前也在飞快的融入计量经济学研究。表面

    2024年02月10日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包