Limited access

Upgrade to access all content for this subject

A selection sort performs one swap if necessary each time through its loop.

Which of the following sections of code will successfully swap the integers at positions x and y in array nums so that the end result is that nums[x] contains the original value from nums[y] and nums[y] contains the original value from nums[x]?

I.

nums[x] = nums[y];
nums[y] = nums[x];

II.

int t = nums[x];
nums[x] = nums[y];
nums[y] = t;

III.

int t = nums[y];
nums[x] = nums[y];
nums[y] = t;
A

I only.

B

II only.

C

III only.

D

I and II only.

E

I, II, and III.

Select an assignment template