Find an Online Tutor Now
C

Rosg R.

asked • 02/04/15

can you tell me the wrong

int main() {
int x,n,d,c,swap,array[d],swap
scanf("%d", &x);
switch (x) {
case 1: mergeSort(...);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}

break;
case 2: bubbleSort(...);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
break;
default: printf("Invalid choice\n");
}
return 0;
}

Jon P.

tutor
What is the program supposed to do?
 
I don't understand the reason for having two nested loops.  There may be a good reason, but without understanding the program, I can't tell.
Report

02/05/15

1 Expert Answer

By:

George A. answered • 03/04/15

Tutor
4.8 (10)

Detail oriented, patient tutor in math, chermistry , programming

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.