Menu

Returns New List Characters Formed Shuffling Characters Given List Precondition Given List Q43838533

* Returns a new list of characters formed by shuffling the * characters of the given list. It is a precondition that * the gi

* Returns a new list of characters formed by shuffling the * characters of the given list. It is a precondition that * the given list t contains at least two elements, and that * the number of elements is an even number. The list is not * modified by this method. * <p> * To shuffle the characters in t, imagine splitting the list t in half so that the first (n / 2) characters of t are in * one sublist, and the remaining (n / 2) characters of t are * in the second sublist. The new returned list is formed by * adding the first character of the first sublist to the * new list, then adding the first character of the second sublist, * then adding the second character of the first sublist, then * adding the second character of the second sublist, and so on, * until all of the characters in the two sublists are added to the new list. * <p> * For example, if t was the list: * <pre> * [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’] * </pre> * <p> * then splitting t into two sublists yields: * <pre> [‘a’, ‘b’, ‘c’] and [‘d’, ‘e’, ‘f’] * </pre> * <p> * Take the first two characters of each sublist and add them to the * new list: * <pre> * [‘a’, ‘d’] * </pre> * <p> * Then take the next two characters of each sublist and add them to the * new list: * <pre> * [‘a’, ‘d’, ‘b’, ‘e’] * </pre> * <p> * Then take the next two characters of each sublist and add them to the * new list: * spre> * [‘a’, ‘d’, ‘b’, ‘e’, ‘c’, ‘f’] * </pre> * @param t a non-null list of characters * @return a new list equal to the shuffle of the characters in t * @pre. t is not null * @pre. t.size() is greater than or equal to 2 * @pre. t.size() is an even number */ public static List<Character> shuffle(List<Character> t) { Show transcribed image text * Returns a new list of characters formed by shuffling the * characters of the given list. It is a precondition that * the given list t contains at least two elements, and that * the number of elements is an even number. The list is not * modified by this method. * * To shuffle the characters in t, imagine splitting the list t in half so that the first (n / 2) characters of t are in * one sublist, and the remaining (n / 2) characters of t are * in the second sublist. The new returned list is formed by * adding the first character of the first sublist to the * new list, then adding the first character of the second sublist, * then adding the second character of the first sublist, then * adding the second character of the second sublist, and so on, * until all of the characters in the two sublists are added to the new list. * * For example, if t was the list: * * [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’] * * * then splitting t into two sublists yields: * [‘a’, ‘b’, ‘c’] and [‘d’, ‘e’, ‘f’] * * * Take the first two characters of each sublist and add them to the * new list: * * [‘a’, ‘d’] * * * Then take the next two characters of each sublist and add them to the * new list: * * [‘a’, ‘d’, ‘b’, ‘e’] * * * Then take the next two characters of each sublist and add them to the * new list: * spre> * [‘a’, ‘d’, ‘b’, ‘e’, ‘c’, ‘f’] * * @param t a non-null list of characters * @return a new list equal to the shuffle of the characters in t * @pre. t is not null * @pre. t.size() is greater than or equal to 2 * @pre. t.size() is an even number */ public static List shuffle(List t) {

Expert Answer


Answer to * Returns a new list of characters formed by shuffling the * characters of the given list. It is a precondition that * t…

OR