def test_peek(self):
		my_stack.push(3)
		my_stack.push(5)

		self.assertEqual(5, my_stack.peek())
		self.assertEqual(3, my_stack.peek(1))
		self.assertEqual(5, my_stack.peek())
Example #2
0
	def test_peek(self):
		my_stack.push(3)
		my_stack.push(5)

		self.assertEqual(my_stack.peek(), 5)
		self.assertEqual(my_stack.peek(1), 3)
		self.assertEqual(my_stack.peek(), 5)
Example #3
0
    def test_peek(self):
        my_stack.push(7)
        my_stack.push(3)
        my_stack.push(5)

        self.assertEqual(5, my_stack.peek())
        self.assertEqual(3, my_stack.peek(1))
        self.assertEqual(5, my_stack.peek())

        self.assertIsNone(my_stack.peek(100),
                          msg="Should return None if no elements")
Example #4
0
def dfs(g: nx.Graph, start_node: Hashable) -> List[Hashable]:
    """
    Do an depth-first search and returns list of nodes in the visited order

    :param g: input graph
    :param start_node: starting node of search
    :return: list of nodes in the visited order
    """
    list_of_visit = []
    push(start_node)
    while peek(0) != None:
        node_now = pop()
        list_of_visit.append(node_now)
        neighbor_list = list(g.neighbors(node_now))
        for i in neighbor_list:
            if i in list_of_visit:
                pass
            else:
                push(i)
    return list_of_visit
Example #5
0
 def test_empty_peek(self):
     self.assertIsNone(my_stack.peek())