This commit is contained in:
Zengtudor 2024-08-03 22:48:00 +08:00
parent 8dd1636ffa
commit a2366cf796
12 changed files with 194 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
#define PRINT_VEC(v) cout<<#v<<" [";for(size_t i=0;i<v.size();i++)cout<<v[i]<<(i!=v.size()-1?",":"]\n");
void sort_fix(vector<int> &v){
for(int i=0;i<v.size();i++){
for(int j=0;j<v.size()-i-1;j++){
if(v[j]>v[j+1]){
swap(v[j],v[j+1]);
}
}
}
}
int main(){
unsigned int n;
cin>>n;
vector<int> v(n);
for(int &i:v){
cin>>i;
}
PRINT_VEC(v);
sort_fix(v);
PRINT_VEC(v);
}

Binary file not shown.

View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
#define PRINT_VEC(v) cout<<#v<<" [";for(size_t i=0;i<v.size();i++)cout<<v[i]<<(i!=v.size()-1?",":"]\n");
void sort_fix(vector<int> &v){
for(size_t i=0;i<v.size()-1;i++){
for(size_t j=0;j<v.size()-i-1;j++){
if(v[j]>v[j+1]){
swap(v[j],v[j+1]);
}
}
}
}
int main(){
unsigned int n;
cin>>n;
vector<int> my_vector(n);
for(int &i:my_vector){
cin>>i;
}
PRINT_VEC(my_vector)
sort_fix(my_vector);
PRINT_VEC(my_vector)
}

Binary file not shown.

View File

@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
#define PRINT_VEC(v){\
cout<<"\n"<<#v<<" [";\
for(size_t i=0;i<v.size();i++){\
cout<<v[i]<<(i!=v.size()-1?",":"]\n");\
}\
}
#define PRINT_VALUE(v){\
cout<<"\n"<<#v<<": "<<v<<"\n";\
}
void sort_fix(vector<int> &v){
for (size_t i=1; i<v.size(); ++i) {
PRINT_VALUE(i)
int key=v[i];
int j=i-1;
while(j>=0&&v[j]>key){
v[j+1]=v[j];
--j;
}
v[j+1]=key;
PRINT_VALUE(v[j+1])
}
}
int main(){
unsigned int n;
cin>>n;
vector<int> v(n);
for(int &i:v){
cin>>i;
}
PRINT_VEC(v);
sort_fix(v);
PRINT_VEC(v);
}

Binary file not shown.

View File

@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;
#define PRINT_VEC(vec){\
cout<<#vec<<" [";\
for(size_t i=0;i<vec.size();i++){\
cout<<vec[i]<<(i!=vec.size()-1?",":"]\n");\
}\
}
void sort_fix(vector<int> &v){
for(size_t i=1;i<v.size();i++){
int key=v[i];
int j=i-1;
while(j>0&&v[j]>key){
v[j+1]=v[j];
--j;
}
v[j+1]=key;
}
}
int main(){
unsigned int n;
cin>>n;
vector<int> v(n);
for(int &i:v){
cin>>i;
}
PRINT_VEC(v)
sort_fix(v);
PRINT_VEC(v)
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
#define PRINT_VEC(v){\
cout<<"\n"<<#v<<" [";\
for(size_t i=0;i<v.size();i++){\
cout<<v[i]<<(i==v.size()-1?"]\n":",");\
}\
}
int n;
void sort_fix(vector<int> &v){
for(int i=0;i<v.size();i++){
int min_num=INT_MAX;
int min_dir=0;
for (int j=i; j<v.size();j++) {
if (min_num>v[j]) {
min_num=v[j];
min_dir=j;
}
}
swap(v[i],v[min_dir]);
}
}
int main(){
cin>>n;
vector<int> vec(n);
for (size_t i=0; i<n; i++) {
cin>>vec[i];
}
PRINT_VEC(vec)
sort_fix(vec);
PRINT_VEC(vec)
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
#define PRINT_VEC(vec){\
cout<<#vec<<" [";\
for(size_t i=0;i<vec.size();i++){\
cout<<vec[i]<<(i!=vec.size()-1?",":"]\n");\
}\
}
void sort_fix(vector<int> &v){
for(size_t i=0;i<v.size();i++){
int min_num=0x7fffffff;
int min_dir=0;
for(size_t j=i;j<v.size();j++){
if (min_num>v[j]) {
min_num=v[j];
min_dir=j;
}
}
swap(v[i],v[min_dir]);
}
}
int main(){
unsigned int n;
cin>>n;
vector<int> v(n);
for(int &i:v){
cin>>i;
}
PRINT_VEC(v)
sort_fix(v);
PRINT_VEC(v)
}