?
The following function represents which sorting?
The following function represents which sorting?
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[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}
if (!swap)
break;
swap = false;
--last;
for (int i = last - 1; i >= first; i--)
{
if (a[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}
++first;
}
}
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[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}
if (!swap)
break;
swap = false;
--last;
for (int i = last - 1; i >= first; i--)
{
if (a[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}
++first;
}
}
Join the Discussion
Login to post a comment or share your explanation.
Login