The following function represents which sorting?
Posted: Wed Jul 13, 2022 6:15 pm
void Sorting(int a[], int n)
{
bool swap = true;
int first = 0;
int last = n - 1;
while (swap)
{
swap = false;
for (int i = first; i < last;i++)
{
if (a > a[i + 1])
{
swap(a, a[i + 1]);
swap = true;
}
}
if (!swap)
break;
swap = false;
--last;
for (int i = last - 1; i >= first; i--)
{
if (a > a[i + 1])
{
swap(a, a[i + 1]);
swap = true;
}
}
++first;
}
}
a) Bubble sort
b) Selection sort
c) Bidirectional bubble sort
d) Odd-even sort
{
bool swap = true;
int first = 0;
int last = n - 1;
while (swap)
{
swap = false;
for (int i = first; i < last;i++)
{
if (a > a[i + 1])
{
swap(a, a[i + 1]);
swap = true;
}
}
if (!swap)
break;
swap = false;
--last;
for (int i = last - 1; i >= first; i--)
{
if (a > a[i + 1])
{
swap(a, a[i + 1]);
swap = true;
}
}
++first;
}
}
a) Bubble sort
b) Selection sort
c) Bidirectional bubble sort
d) Odd-even sort