Question
I am having trouble understanding how this code works could someone break it down for me //search a sorted list for a certain number int[]list=
I am having trouble understanding how this code works could someone break it down for me
//search a sorted list for a certain number
int[]list= new int[20];
int n;
//unsorted list
for(int k=0;k //insert a random number from 0-100 into list so that the list is sorted n =(int) (101*Math.random()); list[k]=n; } System.out.println("Unsorted list"); for(int x: list) System.out.print(x+"\t"); System.out.println(); for(int k=1;k //insert a random number from 0-100 so that the list is sorted n=list[k]; int pos=k-1; while(pos>=0 &&n list[pos+1] = list[pos]; pos--; } list[pos+1]=n; } System.out.println("After insertion sort"); for( int x:list) System.out.print(x+"\t"); System.out.println(); }
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