forked from 131/lab4_sort
izmenila
This commit is contained in:
63
sort.c
63
sort.c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user