upload
This commit is contained in:
commit
810a9654a4
50 changed files with 4450 additions and 0 deletions
49
2/A.cpp
Normal file
49
2/A.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
|
||||
void PrintArray(const int* arr, const int* size);
|
||||
void SortArray(int* arr, const int* size);
|
||||
|
||||
|
||||
void PrintArray(const int* arr, const int* size) {
|
||||
for (int i = 0; i < *size; ++i) {
|
||||
std::cout << arr[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void SortArray(int* arr, const int* size) {
|
||||
if (*size == 1)
|
||||
return;
|
||||
|
||||
int i, j, idx;
|
||||
idx = 0;
|
||||
i = idx;
|
||||
j = 1;
|
||||
|
||||
while (idx < *size) {
|
||||
while (arr[i] > arr[j]) {
|
||||
std::swap(arr[i], arr[j]);
|
||||
if (i == 0)
|
||||
break;
|
||||
--j;
|
||||
--i;
|
||||
}
|
||||
i = idx;
|
||||
j = ++idx;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int size;
|
||||
std::cin >> size;
|
||||
|
||||
int* a = new int[size];
|
||||
for (int i = 0; i < size; ++i) {
|
||||
std::cin >> a[i];
|
||||
}
|
||||
|
||||
SortArray(a, &size);
|
||||
PrintArray(a, &size);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue