1
0
forked from 131/lab4_sort
This commit is contained in:
Ваше Имя
2025-11-22 04:46:17 -05:00
parent 5c66c4f388
commit e633fd3aa2

63
sort.c
View File

@@ -76,28 +76,53 @@ bubble_sort(int *arr, size_t sz)
static void
_merge(int *tmp, int *a, int *b, int *end)
{
int *left = a;
int *right = b;
int *result = tmp;
while (left < b && right < end) {
if (*left <= *right) {
*result++ = *left++;
} else {
*result++ = *right++;
// int *left = a;
// int *right = b;
// int *result = tmp;
//
//
// while (left < b && right < end) {
// if (*left <= *right) {
// *result++ = *left++;
// } else {
// *result++ = *right++;
// }
// }
//
//
// while (left < b) {
// *result++ = *left++;
// }
//
//
// while (right < end) {
// *result++ = *right++;
// }
int a1 = 0, b1 = 0, tmp1 = 0;
int ra = b - a, rb = end - b;
while (ra > a1 && rb > b1)
{
if (a[a1] < b[b1])
{
tmp[tmp1++] = a[a1++];
}
else
{
tmp[tmp1++] = b[b1++];
}
}
while (left < b) {
*result++ = *left++;
}
while (right < end) {
*result++ = *right++;
while (ra != a1)
{
tmp[tmp1] = a[a1];
a1++;
tmp1++;
}
while (rb != b1)
{
tmp[tmp1] = b[b1];
b1++;
tmp1++;
}
}
static void