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:47 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 74 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 no_multiples_of_3(self) which returns False if the linked list contains an integer which is divisible by 3, and returns True otherwise. Submit the entire LinkedList class definition in the answer box below and you can also assume that the linked list contains only integer elements. 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. For example: Test Result True linked_list = LinkedList() linked_list.add(2) linked_list.add(4) linked_list.add(1) linked_list.add(5) print(linked_list.no_multiples_of_30) linked_list = Linkedlist) linked_list.add(2) linked_list.add(4) linked_list.add(6) print(linked_list.no_multiples_of_30) False