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 102return 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返回值即是交集中最后一个元素的下一个位置

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 73return 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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/10298.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

爬虫获取渲染后页面(JAVA)

一、背景 最近突然想了解一下爬虫&#xff0c;但是自己又不太了解python&#xff0c;所以学习了下Java版爬虫。在这个过程中遇到了一个问题&#xff0c;为了解决这个问题&#xff0c;百度了很多方法&#xff0c;两个小时候&#xff0c;终于找到了一个最佳方案 二、问题描述 第…

python与深度学习(八):CNN和fashion_mnist二

目录 1. 说明2. fashion_mnist的CNN模型测试2.1 导入相关库2.2 加载数据和模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章训练的模型进行测…

day43-Feedback Ui Design(反馈ui设计)

50 天学习 50 个项目 - HTMLCSS and JavaScript day43-Feedback Ui Design&#xff08;反馈ui设计&#xff09; 效果 index.html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport&q…

opencv-26 图像几何变换04- 重映射-函数 cv2.remap()

什么是重映射&#xff1f; 重映射&#xff08;Remapping&#xff09;是图像处理中的一种操作&#xff0c;用于将图像中的像素从一个位置映射到另一个位置。重映射可以实现图像的平移、旋转、缩放和透视变换等效果。它是一种基于像素级的图像变换技术&#xff0c;可以通过定义映…

P1012 [NOIP1998 提高组] 拼数

题目描述 设有 &#xfffd;n 个正整数 &#xfffd;1…&#xfffd;&#xfffd;a1​…an​&#xff0c;将它们联接成一排&#xff0c;相邻数字首尾相接&#xff0c;组成一个最大的整数。 输入格式 第一行有一个整数&#xff0c;表示数字个数 &#xfffd;n。 第二行有 &a…

【正规方程对波士顿房价数据集进行预测】

数据准备 我们首先需要加载波士顿房价数据集。该数据集包含房屋特征信息和对应的房价标签。 import pandas as pd import numpy as npdata_url "http://lib.stat.cmu.edu/datasets/boston" raw_df pd.read_csv(data_url, sep"\s", skiprows22, headerN…

安全DNS,状态码,编码笔记整理

一 DNS DNS&#xff08;Domain Name System&#xff09;是互联网中用于将域名转换为IP地址的系统。 DNS的主要功能包括以下几个方面&#xff1a; 域名解析&#xff1a;DNS最主要的功能是将用户输入的域名解析为对应的IP地址。当用户在浏览器中输入一个域名时&#xff0c;操作…

github token使用方法

git remote set-url origin https://<githubtoken>github.com/<username>/<repositoryname>.git 在私有仓库的HTTPS的url上加入<githubtoken>即为token url&#xff0c;可以免ssh key登录

NoSQL之redis配置与优化

NoSQL之redis配置与优化 高可用持久化功能Redis提供两种方式进行持久化1.触发条件手动触发自动触发 执行流程优缺点缺点&#xff1a;优势AOF出发规则&#xff1a; AOF流程AOF缺陷和优点 NoSQL之redis配置与优化 mysql优化 1线程池优化 2硬件优化 3索引优化 4慢查询优化 5内…

iptables与防火墙

目录 防火墙 安全技术 划分方式 iptables 构成 四表 优先级 五链 iptables的规则 匹配顺序 iptables的命令格式 管理选项 匹配条件 控制类型 隐藏扩展模块 注意事项 防火墙 隔离功能&#xff0c;一般部署在网络边缘或者主机边缘&#xff0c;在工作中防火墙的…

Java 悲观锁 乐观锁

锁可以从不同的角都分类。其中乐观锁和悲观锁是一种分类方式 一、悲观锁、乐观锁定义 悲观锁就是我们常说到的锁。对于悲观锁来说&#xff0c;他总是认为每次访问共享资源时会发生冲突&#xff0c;所以必须每次数据操作加上锁&#xff0c;以保证临界区的程序同一时间只能有一个…

从零学算法560

560. 和为 K 的子数组 给你一个整数数组 nums 和一个整数 k &#xff0c;请你统计并返回 该数组中和为 k 的连续子数组的个数 。 示例 1&#xff1a; 输入&#xff1a;nums [1,1,1], k 2 输出&#xff1a;2 示例 2&#xff1a; 输入&#xff1a;nums [1,2,3], k 3 输出&…

SQLite Studio 连接 SQLite数据库

1、在SQLite中创建数据库和表 1.1、按WINR&#xff0c;打开控制台&#xff0c;然后把指引到我们的SQLite的安装路径&#xff0c;输入D:&#xff0c;切换到D盘&#xff0c;cd 地址&#xff0c;切换到具体文件夹&#xff0c;输入“sqlite3”&#xff0c;启动服务 1.2、创建数据库…

多租户分缓存处理

多租户redis缓存分租户处理 那么数据库方面已经做到了拦截&#xff0c;但是缓存还是没有分租户&#xff0c;还是通通一个文件夹里&#xff0c; 想实现上图效果&#xff0c;global文件夹里存的是公共缓存。 首先&#xff0c;那么就要规定一个俗称&#xff0c;缓存名字带有globa…

数据库应用:MySQL MHA高可用集群

目录 一、理论 1.MHA 2.MySQL MHA部署准备 3.MySQL MHA部署 二、实验 1.MHA部署 三、问题 1.中英文符兼容报错 2.MHA测试 ssh 无密码认证语法报错 3.MHA测试 ssh 无密码认证log-bin报错 4.MHA测试 mysql 主从连接情况报错slave replication 5.MHA测试 mysql 主从连…

Elasticsearch监控工具Cerebro安装

Elasticsearch监控工具Cerebro安装 1、在windwos下的安装 1.1 下载安装包 https://github.com/lmenezes/cerebro/releases/download/v0.9.4/cerebro-0.9.4.zip 1.2 解压 1.3 修改配置文件 如果需要修改相关信息&#xff0c;编辑C:\zsxsoftware\cerebro-0.9.4\conf\applica…

腾讯云大数据型CVM服务器实例D3和D2处理器CPU型号说明

腾讯云服务器CVM大数据型D3和D2处理器型号&#xff0c;大数据型D3云服务器CPU采用2.5GHz Intel Xeon Cascade Lake 处理器&#xff0c;大数据型D2云服务器CPU采用2.4GHz Intel Xeon Skylake 6148 处理器。腾讯云服务器网分享云服务器CVM大数据型CPU型号、处理器主频性能&#x…

css3的filter图片滤镜使用

业务介绍 默认&#xff1a;第一个图标为选中状态&#xff0c;其他三个图标事未选中状态 样式&#xff1a;选中状态是深蓝&#xff0c;未选中状体是浅蓝 交互&#xff1a;鼠标放上去选中&#xff0c;其他未选中&#xff0c;鼠标离开时候保持当前选中状态 实现&#xff1a;目前…

算法练习(3):牛客在线编程04 堆/栈/队列

package jz.bm;import java.util.*;public class bm4 {/*** BM42 用两个栈实现队列*/Stack<Integer> stack1 new Stack<>();Stack<Integer> stack2 new Stack<>();public void push(int node) {stack1.push(node);}public int pop() {while (!stack1…

Component template should contain exactly one root element

在vue中报错&#xff1a; Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead报错的大致意思是&#xff1a;组件的模板应该只能包含一个根元素&#xff0c;也就是是说作为元素的直…