当前位置: 首页>>代码示例>>Python>>正文


Python Node.get_next方法代码示例

本文整理汇总了Python中node.Node.get_next方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_next方法的具体用法?Python Node.get_next怎么用?Python Node.get_next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在node.Node的用法示例。


在下文中一共展示了Node.get_next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_2

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import get_next [as 别名]
def convert_2(xs):
    str_buffer = Node(xs[0])
    head = str_buffer
    for i in range(len(xs) - 1):
        str_buffer.set_next(Node(xs[i + 1]))
        str_buffer = str_buffer.get_next()
    return head
开发者ID:agatanyc,项目名称:RC,代码行数:9,代码来源:string_buffer.py

示例2: TestNode

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import get_next [as 别名]
class TestNode(unittest.TestCase):

    def setUp(self):
        self.node1 = Node()
        self.node2 = Node()
        
    def tearDown(self):
        self.node1 = None
        self.node2 = None
    
    def test_get_set_data(self):
        self.node1.set_data(5)
        self.assertEqual(self.node1.get_data(), 5)    
    
    def test_get_set_next(self):
        self.node1.set_next(self.node2)
        self.assertEqual(self.node1.get_next(), self.node2)    
开发者ID:fredgyoung,项目名称:Python-Data-Structures,代码行数:19,代码来源:test_node.py

示例3: PriorityQueue

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import get_next [as 别名]
class PriorityQueue():
    def __init__(self, tasks=[]):
        """
        The function initiates a new PriorityQueue object, creation new Node
        objects for each task on tasks list and putting them on the queue

        :param tasks: list of StringTasks objects, tasks
        :return: None
        """
        self._tasks = tasks
        self._head = None
        self._length = 0
        self._current = None
        self._start = False
        for i in self._tasks:
            # If there are tasks on tasks list, insert each task to the queue
            # using enque()
            self.enque(i)


    def enque(self, task):
        """
        The function insert a new Node with the task to the queue on the right
        position depends on the task's priority

        :param task: StringTask object, new task
        :return: None
        """

        # Add 1 to the length of the queue
        self._length += 1

        if self._head is None:
            # If the queue is empty, just add the task to the queue and set
            # the head to the new task node
            self._head = Node(task)
        elif task.get_priority() > self._head.get_priority():
            # If the queue is not empty and the task priority is larger then
            # the head priority, set the next node of the new task node to the
            # current head and change the head to the new task node
            self._head = Node(task, self._head)
        else:
            # If the queue is not empty and the new task priority is not
            # larger then the head priority
            current_node = self._head
            next_node = current_node.get_next()
            while current_node.has_next():
                if task.get_priority() > next_node.get_priority():
                    # While the current node has a next node, compare the
                    # task priority to the next node priority. If the first
                    # is larger, break the loop
                    break

                # Change the current node to the next node, and the next node
                # to the next-next-node
                current_node = next_node
                next_node = next_node.get_next()

            # Create a new Node for the task pointing to next node (where
            # its priority < the task priority or it is None)
            # and set the next node of the current node (where its priority
            # is >= the task priority to the new task Node
            current_node.set_next(Node(task, next_node))

    def peek(self):
        """
        The function returns the task of the head of queue

        :return: StringTask object, task of head of queue is not empty
                 None if the queue is empty
        """

        if self._head is None:
            # If the queue is empty
            return None
        else:
            # Return the head task without remove it from queue
            return self._head.get_task()

    def deque(self):
        """
        The function returns the task of the head node (if exists) and removes
        the head from queue

        :return: StringTask object, task of head of queue is not empty
                 None if the queue is empty
        """

        if self._head is None:
            # If the queue is empty
            return None
        else:
            # Reduce 1 from the length of the queue
            self._length -= 1

            # Return the head task and remove head from queue
            task = self._head.get_task()
            self._head = self._head.get_next()
            return task

#.........这里部分代码省略.........
开发者ID:idan0610,项目名称:intro2cs-ex11,代码行数:103,代码来源:priority_queue.py


注:本文中的node.Node.get_next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。