Tracing Array Element Swaps
What is printed as a result of executing the main method of the HeapTest class?
public class HeapTest {
public static void main(String[] args) {
int[] heap = {Integer.MIN_VALUE, 10, 20, 30, 40, 50}; // 1-indexed heap; index 0 is unused
// Swap elements at indices 2 and 5
int temp = heap[2];
heap[2] = heap[5];
heap[5] = temp;
// Swap elements at indices 3 and 4
temp = heap[3];
heap[3] = heap[4];
heap[4] = temp;
for(int i = 1; i < heap.length; i++){
System.out.print(heap[i] + " ");
}
}
}
A
10 20 40 30 50
B
10 50 40 30 20
C
10 40 50 30 20
D
10 50 30 40 20
APFIVE