def test_find_in_list(self): names = ("James", "1234", 10), ("Kobe", "3456", 20), ("Curry", "7890", 8) nodes = [Node(matric, name, year) for name, matric, year in names] linked_list = LinkedList() for node in nodes: linked_list.add_to_list(node) marker = linked_list.get_root() for i in range(len(nodes) - 1, -1, -1): self.assertEqual(nodes[i], linked_list.find(marker.name)) marker = marker.get_next()
class LinkedQueue: def __init__(self): self.__linked_list = LinkedList() def get_root(self): return self.__linked_list.get_root() def push(self, node): self.__linked_list.add_to_list(node) def pop(self): marker = self.__linked_list.get_root() if marker is None: raise BaseException("Nothing to be pop!") while marker.get_next(): if marker.get_next().get_next() is None: pop_node = marker.get_next() marker.set_next(None) return pop_node marker = marker.get_next() return self.__linked_list.clear_list() def print_queue(self): self.__linked_list.print_list() def get_size(self): marker = self.__linked_list.get_root() count = 0 while marker: count += 1 marker = marker.get_next() return count def find(self, name): return self.__linked_list.find(name)
def test_find_missing_in_list(self): linked_list = LinkedList() with self.assertRaises(LookupError): linked_list.find("Dust")
from linked_list.node import Node from linked_list.LinkedList import LinkedList nba_menber = LinkedList() nba_menber.add_to_list(Node('aa', 'Kobe', 40)) nba_menber.add_to_list(Node('aa', 'James', 35)) nba_menber.add_to_list(Node('aa', 'Curry', 31)) nba_menber.add_to_list(Node('aa', 'Durant', 30)) nba_menber.add_to_list(Node('aa', 'Kwaii', 28)) # nba_menber.print_list() nba_menber.find("James").print_details()