Сделал 9 Задание на сортировку
This commit is contained in:
parent
a1a35972d4
commit
a83a31c034
4 changed files with 142 additions and 0 deletions
33
Sorting/9Ex/seagwithsob.c
Normal file
33
Sorting/9Ex/seagwithsob.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "seagwithsob.h"
|
||||
|
||||
void sort(double * array, int length) {
|
||||
double zero[length];
|
||||
double unit[length];
|
||||
int index;
|
||||
|
||||
for (int j = 0; j < 63; ++j) {
|
||||
index = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if ((*(unsigned long long*)&array[i] >> j) & 1) unit[index++] = array[i];
|
||||
else zero[i - index] = array[i];
|
||||
}
|
||||
|
||||
rewrite(array, zero, length - index, unit, index);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if ((*(unsigned long long*)&array[i] >> 63) & 1) unit[index++] = array[i];
|
||||
else zero[i - index] = array[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < index; ++i) array[i] = unit[index - i - 1];
|
||||
for (int i = index; i < length; ++i) array[i] = zero[i - index];
|
||||
}
|
||||
|
||||
void rewrite(double * array, double * zero, int len_zero, double * unit, int len_unit) {
|
||||
for (int i = 0; i < len_zero; ++i) array[i] = zero[i];
|
||||
for (int i = len_zero; i < len_zero + len_unit; ++i) array[i] = unit[i - len_zero];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue