Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started