Question: Sorting It is often necessary to sort data. The following piece of code sorts the contents of an integer array called items. int items[10] =

Sorting

It is often necessary to sort data. The following piece of code sorts the contents of an integer array called items.

int items[10] = {1,6,9,5,4,2,8,0,7,3};

void sort()

{

int i;

int j;

int temp;

for (i=0; i<9; i++)

{

for (j=i+1; j<10; j++)

{

if (items[i] > items[j])

{

temp = items[i];

items[i] = items[j];

items[j] = temp;

}

}

}

}

  1. What numbers will be exchanged on the first swap to sort the array?
  1. 1 and 0
  2. 2 and 3
  3. 5 and 6
  4. 4 and 2

  1. What numbers will be exchanged on the second swap to sort the array?
  1. 8 and 7
  2. 5 and 4
  3. 9 and 6
  4. 6 and 5

  1. What numbers will be exchanged on the third swap to sort the array?
  1. 3 and 2
  2. 7 and 0
  3. 5 and 4
  4. 9 and 5

  1. What numbers will be exchanged on the fourth swap to sort the array?
  1. 7 and 0
  2. 5 and 4
  3. 4 and 2
  4. 6 and 3

  1. What numbers will be exchanged on the fifth swap to sort the array?
  1. 2 and 1
  2. 5 and 4
  3. 8 and 3
  4. 6 and 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!