c++
A snicker
努力吧
展开
-
C++—快速排序
快速排序 int partition(int a[], int left, int right) { //快排 int x = a[left]; while (left < right) { while (left < right && a[right] >= x) { right--; } a[left] = a[right]; while (left < right && a[left] <= x) {原创 2021-04-24 14:13:12 · 70 阅读 · 0 评论 -
memset函数赋值
给一个二维数组全部赋值,用memset函数(包含头文件string.h就可以使用了) #include<iostream> #include<string.h> using namespace std; int main() { int s[100][100]; memset(s, -1, sizeof(s)); cout << s[1][1]; }原创 2021-06-16 16:08:00 · 413 阅读 · 0 评论 -
Sort()函数用法:比较函数写法
sort 函数 sort函数可以三个参数也可以两个参数,必须包含头文件 #include < algorithm> using namespace std; 12 它使用的排序方法是类似于快排的方法,时间复杂度为o(nlog(n)) Sort函数有三个参数:(第三个参数可不写) (1)第一个是要排序的数组的起始地...转载 2021-06-16 15:22:02 · 604 阅读 · 0 评论 -
C++ max_element()的使用
max_element是用来来查询最大值所在的第一个位置。 max_element有两种写法,第一种是从头迭代器到尾迭代器用自己写的方法去比较, 第二种是直接用它自带的头迭代器到尾迭代器的比较大小。 #include <algorithm> #include <iostream> using namespace std; struct structs { bool operator() (int i, int j) { return i<j; } } struct原创 2021-05-09 13:02:59 · 241 阅读 · 0 评论