update
This commit is contained in:
parent
8dd1636ffa
commit
a2366cf796
BIN
day2/review_exam/冒泡排序/main
Executable file
BIN
day2/review_exam/冒泡排序/main
Executable file
Binary file not shown.
26
day2/review_exam/冒泡排序/main.cpp
Normal file
26
day2/review_exam/冒泡排序/main.cpp
Normal 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);
|
||||
}
|
BIN
day2/review_exam/冒泡排序/second
Executable file
BIN
day2/review_exam/冒泡排序/second
Executable file
Binary file not shown.
26
day2/review_exam/冒泡排序/second.cpp
Normal file
26
day2/review_exam/冒泡排序/second.cpp
Normal 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)
|
||||
}
|
BIN
day2/review_exam/插入排序/main
Executable file
BIN
day2/review_exam/插入排序/main
Executable file
Binary file not shown.
39
day2/review_exam/插入排序/main.cpp
Normal file
39
day2/review_exam/插入排序/main.cpp
Normal 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);
|
||||
}
|
BIN
day2/review_exam/插入排序/second
Executable file
BIN
day2/review_exam/插入排序/second
Executable file
Binary file not shown.
33
day2/review_exam/插入排序/second.cpp
Normal file
33
day2/review_exam/插入排序/second.cpp
Normal 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)
|
||||
}
|
BIN
day2/review_exam/选择排序/main
Executable file
BIN
day2/review_exam/选择排序/main
Executable file
Binary file not shown.
35
day2/review_exam/选择排序/main.cpp
Normal file
35
day2/review_exam/选择排序/main.cpp
Normal 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)
|
||||
}
|
BIN
day2/review_exam/选择排序/second
Executable file
BIN
day2/review_exam/选择排序/second
Executable file
Binary file not shown.
35
day2/review_exam/选择排序/second.cpp
Normal file
35
day2/review_exam/选择排序/second.cpp
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user