排序大联欢
不多说了,各种排序,写的很简洁,适合自行学习。
: 排序大联欢C++语言
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<bitset>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<cctype>
#include<complex>
#include<list>
#include<limits>
#define pgg printf ( "GG\n" );
#define pgs(a) printf("GG %s\n", a);
#define pg(a) printf("GG %d\n", a)
#define re(i,n) for(int (i) = 0; (i) < int(n); ++i)
//div M_PI time left count distance 不能用哦,已经定义了。
using namespace std;
typedef long long ll;
template<class T>
void inline maxi(T &a, const T &b){
a=max(a,b);
}
template<class T>
void inline mini(T &a,const T &b){
a = min(a, b);
}
void shownum(int n,int m, int W = 6){
for(int i = n; i <= m; ++i){
cout << setw(W) << i;
}
cout << endl;
}
template<class T>
void show(T &a,int n,int m, int W = 6){
for(int i = n; i <= m; ++i){
cout << setw(W) <<a[i];
}
cout << endl;
}
template<class T>
void show(T &a, int W = 6){
re(u, a.size()){
cout << setw(W) << a[u];
}
cout << endl;
}
const int maxnum = +10;
const int maxint = numeric_limits<int>::max();
const int minint = numeric_limits<int>::min();
//const ll maxll = numeric_limits<ll>::max();
//const ll minll = numeric_limits<ll>::min();
int l[] = {
-1, -2, 99, 100, 100, 200, 100, -87, 98, 99
//-2, -1, 1, 2, 3, 2, 3, 3, 3, 10
};
const int n = sizeof(l) / sizeof(int);
int tmp[n];
void insert(){
for(int j = 1; j < n; ++j){
int v = l[j];
int i = j - 1;
while(i >= 0 && v < l[i]){
l[i + 1] = l[i];
i--;
}
l[i + 1] = v;
}
}
void maopao(){
int b = n - 1;
while(1){
int t = -1;
for(int i = 0; i < b ; ++i){
if(l[i] > l[i + 1]){
swap(l[i], l[i + 1]);
t = i;
}
}
if(t == -1)
break;
b = t;
}
}
int pa(int left, int right){
int x = l[right];
int i = left;
for(int j = left; j < right; ++j){
if(l[j] < x){
swap(l[i++], l[j]);
}
}
swap(l[i], l[right]);
return i;
}
void qsort(int left, int right){
if(right <= left) return;
int p = pa(left, right);
qsort(left, p - 1);
qsort(p + 1, right);
}
void merge(int left, int right){
//if(right <= left) return;
int p = left, m = (left + right) / 2, q = m + 1, i = p;
while(p <= m || q <= right){
if(p > m || (q <= right && l[q] <= l[p])) tmp[i++] = l[q++];
else tmp[i++] = l[p++];
}
for(int i = left; i <= right; ++i) l[i] = tmp[i];
}
void msort(int left, int right){
if(right <= left) return;
int mid = (left + right) / 2;
msort(left, mid);
msort(mid + 1, right);
//show(tmp, 0, n - 1);
merge(left, right);
//show(tmp, 0, n - 1);
}
void choose(){
for(int i = 0; i < n - 1; ++i){
int k = i;
int big = l[i];
for(int j = i + 1; j < n; ++j){
if(big > l[j]){
big = l[j];
k = j;
}
}
swap(l[i], l[k]);
}
}
void mmain(){
memset(tmp, 0, sizeof(tmp));
show(l, 0, n - 1);
//insert();
//maopao();
//qsort(0, n - 1);
//msort(0, n - 1);
//choose();
show(l, 0, n - 1);
}
//#define codeforces CODEFORCES
#define codeforces_input CODEFORCES_FILE
#define MANY_TEST CODEFORCES_MANY_TEST
#define MANY_TESST 3
int main(){
#ifdef codeforces
#ifdef codeforces_input
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
#ifdef MANY_TEST
re(bbbbbwwwwww,MANY_TESST)
mmain();
return 0;
#endif
#endif
mmain();
}
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<bitset>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<cctype>
#include<complex>
#include<list>
#include<limits>
#define pgg printf ( "GG\n" );
#define pgs(a) printf("GG %s\n", a);
#define pg(a) printf("GG %d\n", a)
#define re(i,n) for(int (i) = 0; (i) < int(n); ++i)
//div M_PI time left count distance 不能用哦,已经定义了。
using namespace std;
typedef long long ll;
template<class T>
void inline maxi(T &a, const T &b){
a=max(a,b);
}
template<class T>
void inline mini(T &a,const T &b){
a = min(a, b);
}
void shownum(int n,int m, int W = 6){
for(int i = n; i <= m; ++i){
cout << setw(W) << i;
}
cout << endl;
}
template<class T>
void show(T &a,int n,int m, int W = 6){
for(int i = n; i <= m; ++i){
cout << setw(W) <<a[i];
}
cout << endl;
}
template<class T>
void show(T &a, int W = 6){
re(u, a.size()){
cout << setw(W) << a[u];
}
cout << endl;
}
const int maxnum = +10;
const int maxint = numeric_limits<int>::max();
const int minint = numeric_limits<int>::min();
//const ll maxll = numeric_limits<ll>::max();
//const ll minll = numeric_limits<ll>::min();
int l[] = {
-1, -2, 99, 100, 100, 200, 100, -87, 98, 99
//-2, -1, 1, 2, 3, 2, 3, 3, 3, 10
};
const int n = sizeof(l) / sizeof(int);
int tmp[n];
void insert(){
for(int j = 1; j < n; ++j){
int v = l[j];
int i = j - 1;
while(i >= 0 && v < l[i]){
l[i + 1] = l[i];
i--;
}
l[i + 1] = v;
}
}
void maopao(){
int b = n - 1;
while(1){
int t = -1;
for(int i = 0; i < b ; ++i){
if(l[i] > l[i + 1]){
swap(l[i], l[i + 1]);
t = i;
}
}
if(t == -1)
break;
b = t;
}
}
int pa(int left, int right){
int x = l[right];
int i = left;
for(int j = left; j < right; ++j){
if(l[j] < x){
swap(l[i++], l[j]);
}
}
swap(l[i], l[right]);
return i;
}
void qsort(int left, int right){
if(right <= left) return;
int p = pa(left, right);
qsort(left, p - 1);
qsort(p + 1, right);
}
void merge(int left, int right){
//if(right <= left) return;
int p = left, m = (left + right) / 2, q = m + 1, i = p;
while(p <= m || q <= right){
if(p > m || (q <= right && l[q] <= l[p])) tmp[i++] = l[q++];
else tmp[i++] = l[p++];
}
for(int i = left; i <= right; ++i) l[i] = tmp[i];
}
void msort(int left, int right){
if(right <= left) return;
int mid = (left + right) / 2;
msort(left, mid);
msort(mid + 1, right);
//show(tmp, 0, n - 1);
merge(left, right);
//show(tmp, 0, n - 1);
}
void choose(){
for(int i = 0; i < n - 1; ++i){
int k = i;
int big = l[i];
for(int j = i + 1; j < n; ++j){
if(big > l[j]){
big = l[j];
k = j;
}
}
swap(l[i], l[k]);
}
}
void mmain(){
memset(tmp, 0, sizeof(tmp));
show(l, 0, n - 1);
//insert();
//maopao();
//qsort(0, n - 1);
//msort(0, n - 1);
//choose();
show(l, 0, n - 1);
}
//#define codeforces CODEFORCES
#define codeforces_input CODEFORCES_FILE
#define MANY_TEST CODEFORCES_MANY_TEST
#define MANY_TESST 3
int main(){
#ifdef codeforces
#ifdef codeforces_input
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
#ifdef MANY_TEST
re(bbbbbwwwwww,MANY_TESST)
mmain();
return 0;
#endif
#endif
mmain();
}