What is the output for the following? Do a trace line by linefor an array with 4
ID: 3613114 • Letter: W
Question
What is the output for the following? Do a trace line by linefor an array with 4 elements: 3333, 1234, 2222, 1000.---
10 public static void insertionSort(int[] list) 11 { 12 int temp; 13 int j; 14 15 for(int i=1;i<list.length;i++) 16 { 17 temp=list[i]; 18 for(j=1;j>0 && temp<list[j-1];j--) 19 { 20 list[j]=list[j-1]; 21 } 22 list[j]=temp; 23 } 24 } 25 }
What is the output for the following? Do a trace line by linefor an array with 4 elements: 3333, 1234, 2222, 1000.
---
10 public static void insertionSort(int[] list) 11 { 12 int temp; 13 int j; 14 15 for(int i=1;i<list.length;i++) 16 { 17 temp=list[i]; 18 for(j=1;j>0 && temp<list[j-1];j--) 19 { 20 list[j]=list[j-1]; 21 } 22 list[j]=temp; 23 } 24 } 25 }
Explanation / Answer
What is the output for the following? Do a trace line by linefor an array with 4 elements: 3333, 1234, 2222, 1000.---
10 public static void insertionSort(int[] list) 11 { 12 int temp; 13 int j; 14 15 for(int i=1;i<list.length;i++) 16 { 17 temp=list[i]; 18 for(j=1;j>0 && temp<list[j-1];j--) 19 { 20 list[j]=list[j-1]; 21 } 22 list[j]=temp; 23 } 24 } 25 }
trace-sorry about the condition done in notepad and copied andpasted
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.