本文整理汇总了Python中LinkedList.remove方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.remove方法的具体用法?Python LinkedList.remove怎么用?Python LinkedList.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.remove方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StackList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
class StackList(object):
"""Clase stack implementada sobre LinkedList"""
def __init__(self):
""" Crea una LinkedList vacia"""
self.llista = LinkedList()
def push(self, data):
""" Agrega un elemento a la pila"""
self.llista.insertBefore(data)
def pop(self):
""" Saca un elemento de la pila y lo retorna"""
if self.llista.isEmpty(): raise IndexError, "La pila esta vacia"
aux = self.llista.getHead()
self.llista.remove()
return aux
def head(self):
""" Devuelve el primer elemento que saldra de la pila, pero no lo borra """
if self.llista.isEmpty(): raise IndexError, "La pila esta vacia"
return self.llista.getHead()
def purge(self):
""" Elimina todos los elementos de la pila"""
self.llista.clear()
def __len__(self):
""" Numero de elementos de la pila"""
return self.llista.getSize()
def __str__(self):
""" Devuelve una cadena de caracteres """
return str(self.llista)
示例2: LinkedList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
def test_when_3_items_have_been_added_and_last_one_removed_then__get_last__should_return_second_item_with_no_next_node(self):
linked_list = LinkedList()
linked_list.add('test item 0')
linked_list.add('test item 1')
linked_list.add('test item 2')
linked_list.remove(2)
last_node = linked_list.get_last()
self.assertEqual(last_node.value, 'test item 1')
self.assertIsNone(last_node.next_node)
示例3: test_when_3_items_have_been_added_and_then_first_item_removed_3_times_count_should_be_0
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
def test_when_3_items_have_been_added_and_then_first_item_removed_3_times_count_should_be_0(self):
linked_list = LinkedList()
linked_list.add('test item 0')
linked_list.add('test item 1')
linked_list.add('test item 2')
linked_list.remove(0)
linked_list.remove(0)
linked_list.remove(0)
self.assertEqual(linked_list.count, 0)
示例4: removeElements
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
list = LinkedList(head)
list.remove(val)
return list.head()
示例5: StackList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
class StackList(object):
"""
StackList
"""
def __init__(self):
self.llista=LinkedList() # Initialize value
"""
Introdueix un element a la llista utilitzant el metode de la LinkedList.
:param:data, dada a introduir
:return: None
"""
def push(self, data):
# Type code here
self.llista.insertAfter(data)
"""
Extreu un element a la llista utilitzant el metode de la LinkedList.
:return: data Conte l'informació del node
"""
def pop(self):
# Type code here
data=self.llista.getTail()
self.llista.remove();
return data;
"""
Retorna l'element el primer element de la pila.
:return: data
"""
def head(self):
# Type code here
return self.llista.getTail()
"""
Esborra el contingut de tota la pila.
:return: None
"""
def purge(self):
self.llista.clear()
"""
Metode que s'utilitza per implementar la funcio len(). .
:param:data, dada a introduir
:return: int Longitud de la pila
"""
def __len__(self):
# Type code here
return self.llista.getSize()
"""
Metode que s'utilitza per implementar la funcio print().
:return string Retorna una cadena amb tots els elements de la pila.
"""
def __str__(self):
# Type code here
return self.llista.__str__()
示例6: test__remove__when_one_item_have_been_added_and_then_removed_then_count_should_be_0
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
def test__remove__when_one_item_have_been_added_and_then_removed_then_count_should_be_0(self):
linked_list = LinkedList()
linked_list.add('test item 0')
linked_list.remove(0)
self.assertEqual(linked_list.count, 0)
示例7: test_when_1_item_have_been_added_and_removed_then_last_item_should_not_be_present
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove [as 别名]
def test_when_1_item_have_been_added_and_removed_then_last_item_should_not_be_present(self):
linked_list = LinkedList()
linked_list.add('test item 0')
linked_list.remove(0)
self.assertIsNone(linked_list.get_last())