#pragma once classMargeSort { public: staticvoidsort(vector<int>& arr); staticvoidprogress(vector<int>&, int left, int right); staticvoidmarge(vector<int>&, int left, int right, int mid); private: };
while (p2 <= right) { help.push_back(arr[p2++]); }
for (int i = 0; i < right - left + 1; i++) { arr[i + left] = help[i]; }
help.clear(); }
附:C++对数器
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#pragma once #include<iostream> #include<random> #include<stdio.h> #include<stdlib.h> #include<windows.h> usingnamespace std;
voidprint_arr(vector<int>& arr, int length); intrandom(int min, int max); voidswap(int* a, int* b); voidcopy_arr(int* source, int* destination, int length); voidrandom_arr(vector<int>& arr, int length, int min, int max); voidset_font_color(WORD color);
voidcopy_arr(int* source, int* destination, int length){ for (int i = 0; i < length; i++) { destination[i] = source[i]; } }
1 2 3 4 5 6 7 8 9 10 11 12 13
#pragma once #include<vector> #include<algorithm> usingnamespace std;
classCompare { public: staticvoiddo_(int number, void(*custom_sort)(vector<int>&), int length, int min, int max); private: staticbooldo_(void (*custom_sort)(vector<int>&), int length, int min, int max); staticbooldo_(vector<int>& arr1, vector<int>& arr2, int length); };