In Part I of Challenge 67, option A best describes the method. The program starts by assigning the int variable n as the length of the String list items. The int variable m is created, equaling n − 1. Then, a for statement is used to make m equal to the element number of the greatest value of items. After that, a String variable named temp is used to switch the values of elements m and n − 1. This process is repeated with the value of n decreased by 1 until n = 1, resulting in the list being sorted in alphabetical order. Because this process best describes Sequential Search, option A is correct.
In Part II of Challenge 67, after two iterations of the while loop, the order of names will be: {“Boris”, “Alice”, “Claire”, “Dan”, “Evan”}. This is because of names’s original order: {“Dan”, “Alice”, “Claire”, “Evan”, “Boris”}. The first iteration of the while statement will compare element 4 (“Boris”) with the others and switch it with the largest of the elements before it: element 3 (“Evan”). The second iteration of the while statement will compare element 3 (“Boris”) with the others and again switch it with the largest of the elements before it: element 0 (“Dan”). This will result in the order of names being: {“Boris”, “Alice”, “Claire”, “Dan”, “Evan”}.
−Phoenix
No comments:
Post a Comment