Consider the LinkedList class implementation in the answer box. Extend the LinkedList class by adding the method running
Posted: Tue May 24, 2022 7:44 am
Consider the LinkedList class implementation in the answer box. Extend the LinkedList class by adding the method running_sum(self) which updates the value of each node in the linked list such that each node contains the running sum of the values in the nodes in the linked list up to and including the current node. For example, if the linked list contains the following values: 1 -> 2 -> 3, then the method updates the linked list and the result is: 1 -> 3 -> 6. Note: Submit the entire LinkedList class definition in the answer box below. This method updates the LinkedList object and it does not return anything. IMPORTANT: A Node implementation is provided to you as part of this exercise - you should not define your own Node class. Instead, your code can make use of any of the Node ADT data fields (e.g. data and next) and methods. For example: Test Result 4 -> 3 -> 2 -> 1 -> None my_list = LinkedList() my_list.add (1) my_list.add(2) 4 -> 7 -> 9 -> 10 -> None my_list.add(3) my_list.add(4) print (my_list) my_list.running_sum() print (my_list)
Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Reset answer 1 class LinkedList: ▼ 2, def __init__(self): 3 self. head = None self.count 6 def add(self, item): #change this method to update self.count new_node = Node(item, self.head) 7 self.head new_node self.count += 1 def _str__(self): if self.head != None: result current = self.head while current: "1 result = result + str(current) + current current.next return result + "None" return N 8 9 10 11- 12, 13 14 15- 16 17 18 19 20 ▼ else: