Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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;
}
}
}
}
- What numbers will be exchanged on the first swap to sort the array?
- 1 and 0
- 2 and 3
- 5 and 6
- 4 and 2
- What numbers will be exchanged on the second swap to sort the array?
- 8 and 7
- 5 and 4
- 9 and 6
- 6 and 5
- What numbers will be exchanged on the third swap to sort the array?
- 3 and 2
- 7 and 0
- 5 and 4
- 9 and 5
- What numbers will be exchanged on the fourth swap to sort the array?
- 7 and 0
- 5 and 4
- 4 and 2
- 6 and 3
- What numbers will be exchanged on the fifth swap to sort the array?
- 2 and 1
- 5 and 4
- 8 and 3
- 6 and 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started