Page 1 of 1

The Node class and LinkedList class are defined as below: class Node: def __init__(self, data, next = None): self.data =

Posted: Sat May 14, 2022 2:45 pm
by answerhappygod
The Node Class And Linkedlist Class Are Defined As Below Class Node Def Init Self Data Next None Self Data 1
The Node Class And Linkedlist Class Are Defined As Below Class Node Def Init Self Data Next None Self Data 1 (29.91 KiB) Viewed 83 times
The Node class and LinkedList class are defined as below: class Node: def __init__(self, data, next = None): self.data = data self.next = next def get_data(self): return self.data def get_next(self): return self.next def set_data(self, new_data): self data = new_data def set_next(self, new_next): self.next = new_next class LinkedList: def __init__(self): self. head = None self.count = 0 def add(self, item): new_node - Node(item, self.head) self.head = new_node self.count += 1 def is_empty(self): return self.count == 0 def size(self): return self.count def search(self, item): current - self.head while current: if current. data == item: return True current = current.next return false def remove(self, item): #change this method to update self.count found = False current = self.head previous = None while current is not None and not found: if current.data == item: found - True else: previous = current current = current.next

if found: if previous None: self.head= current.next else: previous.set_next(current.next) self.count -- 1

Continuing on with your LinkedList class implementation, extend the LinkedList class by adding the method get_total_word_scores(self) which returns the sum of the word scores in this linked chain of nodes. For example, if the linked list contains the following values: 'hello' -> 'to' -> 'programming, then the result is 200 as the score for 'hello' is 47, 'to' is 33 and programming' is 120. Each letter in the Node is assigned a score based on the position of the letter in the alphabet. The letter "a" would have a score of O, the letter "b" would have a score of 1 and so on. Note: • You can assume that the parameter is a valid Node object and all nodes contain lowercase string elements only. • The calculation of a word score is done in the Node class's get_word_score() method. 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 and methods (e.g. get_word_score(). For example: Test Result 87 linked_list - Linkedlist) linked_list.add("bob") linked_list.add("sarah") linked_list.add("fred") print(linked_list.get_total_word_scores)