Question: (10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You


(10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You may ONLY use the following methods of Positional ADT and List ADT. You may use the foreach loop in the form of "fora in collection". You may also assume the iterator will return the element in the correct order from the first element to the last element. List ADT: Positional ADT: isEmptyO, size, iterator isEmptyO, size, iterator. positions get(i). after position), before(position), first, last(). addi, E) addAfter position. E) addBefore(position. E), addFirst(E), set(i.) addLast(E) remove(1) set(position, E) remove(position,e). 2) Write code to insert data into a sorted positional list L. [IMPORTANT Note: L is a Positional List type. Use the correct way to access L. For example, if you want to get the first element in the list, don't do L head which is a specific implementation of Positional List, but use L.first(). See the methods for List above] Alg insert (L, x) Input: L is a min to max sorted positional list of integers. x is a integer that will be added to the list. Output: x is inserted to L at the appropriate location so data is still sorted from min to max (10 points) Complete the following two algorithms to insert an new value to a sorted index List and a sorted positional list of integers. You may ONLY use the following methods of Positional ADT and List ADT. You may use the foreach loop in the form of "fora in collection". You may also assume the iterator will return the element in the correct order from the first element to the last element. List ADT: Positional ADT: isEmptyO, size, iterator isEmptyO, size, iterator. positions get(i). after position), before(position), first, last(). addi, E) addAfter position. E) addBefore(position. E), addFirst(E), set(i.) addLast(E) remove(1) set(position, E) remove(position,e). 2) Write code to insert data into a sorted positional list L. [IMPORTANT Note: L is a Positional List type. Use the correct way to access L. For example, if you want to get the first element in the list, don't do L head which is a specific implementation of Positional List, but use L.first(). See the methods for List above] Alg insert (L, x) Input: L is a min to max sorted positional list of integers. x is a integer that will be added to the list. Output: x is inserted to L at the appropriate location so data is still sorted from min to max
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
