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
|
static void
|
||||||
_merge(int *tmp, int *a, int *b, int *end)
|
_merge(int *tmp, int *a, int *b, int *end)
|
||||||
{
|
{
|
||||||
int *left = a;
|
// int *left = a;
|
||||||
int *right = b;
|
// int *right = b;
|
||||||
int *result = tmp;
|
// int *result = tmp;
|
||||||
|
//
|
||||||
|
//
|
||||||
while (left < b && right < end) {
|
// while (left < b && right < end) {
|
||||||
if (*left <= *right) {
|
// if (*left <= *right) {
|
||||||
*result++ = *left++;
|
// *result++ = *left++;
|
||||||
} else {
|
// } else {
|
||||||
*result++ = *right++;
|
// *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 (ra != a1)
|
||||||
|
{
|
||||||
while (left < b) {
|
tmp[tmp1] = a[a1];
|
||||||
*result++ = *left++;
|
a1++;
|
||||||
}
|
tmp1++;
|
||||||
|
|
||||||
|
|
||||||
while (right < end) {
|
|
||||||
*result++ = *right++;
|
|
||||||
}
|
}
|
||||||
|
while (rb != b1)
|
||||||
|
{
|
||||||
|
tmp[tmp1] = b[b1];
|
||||||
|
b1++;
|
||||||
|
tmp1++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user