示例#1
0
    def test_add_to_list(self):
        name = "Dust"
        matric = "1234"
        year = 3

        node = Node(matric, name, year)
        linked_list = LinkedList()
        linked_list.add_to_list(node)

        self.assertEqual(linked_list.get_root(), node)
示例#2
0
    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()
示例#3
0
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)
示例#4
0
    def test_list_creation(self):
        linked_list = LinkedList()

        self.assertIsNone(linked_list.get_root())