关于algorithm头文件常用的函数

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <string>
 4 using namespace std;
 5 int main()
 6 {
 7     int a = 10;
 8     int b = 5;
 9     int c = 12;
10     swap(a, b);//交换
11     cout << a << endl;
12     cout << b << endl;
13     cout << max(a, b) << endl;//求两数最大
14     cout << max(a, max(b,c)) << endl;
15     cout << min(a, c) << endl;
16     string s = "abcdef";
17     reverse(s.begin(),s.end());
18     for (int i=0;i<s.length();++i)
19     {
20         cout << s[i];
21     }
22     cout << endl;
23     int d[5] = { 1,2,3,4,5 };
24     fill(d, d + 3, 6);//指定范围填充数
25     for (int i=0;i<5;++i)
26     {
27         cout << d[i];
28     }
29     return 0;
30 }

还有个sort函数,见stl篇

posted @ 2020-12-02 22:34  丁帅帅dss  阅读(92)  评论(0)    收藏  举报