Question: Document an algorithm cool (L, target): The inputs into the algorithm are a positional list of unique (no duplicates) integers, and an integer target element

Document an algorithm cool (L, target): The inputs into the algorithm are a positional list of unique (no duplicates) integers, and an integer target element to find The algorithm should locate the target element (if it exists in the list), double its value, and move it forward toward the head of the list) by 2 positions. If the target element is originally the first position of the list, double the value of the element and move the position with the element to the tail of the list. If the target element is originally the 2nd position in the list, double the value of the element and move the position with the element to the tail of the list. If the target value is not in the list, return null. Otherwise, return the position of the doubled target element after it is relocated. The algorithm must use only the positional list abstract data type behaviors/operations described in lecture Examples: Given the list: [ P[1], P[2], P[3], P[4], P[5] ] and target element 3 The final list: [ P[6], P[1], P[2], P[4], P[5] ] Return: P[6] Given the list: [ P[1], P[2], P[3], P[4], P[5] ] and target element 2 The final list: [ P[1], P[3], P[4], P[5], P[4] ] Return: P[4]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
