Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

=+1 Why are local employment laws important to IHRM?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago