本文整理匯總了Python中LinkedList.LinkedList.clear方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.clear方法的具體用法?Python LinkedList.clear怎麽用?Python LinkedList.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.clear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: LLQueue
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import clear [as 別名]
class LLQueue(object):
def __init__(self, size=0):
self._list = LinkedList()
self._size = size
def enqueue(self, data):
if (self._size > 0 and self._list.count < self._size):
self._list.add(data)
else:
raise Exception("Too many items in the queue")
def dequeue(self):
if (self._list.count == 0):
raise Exception("No items in the queue")
node = self._list[0]
del self._list[0]
return node
def isEmpty(self):
return (self._list.count == 0)
def clear(self):
self._list.clear()
@property
def size(self):
return self._size
def __len__(self):
return len(self._list)
示例2: comment
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import clear [as 別名]
comment("OK -> " + test_name)
grade(points['ll_1e_remove'])
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)
# Check one element list - clear()
try:
test_name = 'LinkedList con un elemento: clear()'
l = LinkedList()
l.insertAfter(17)
l.clear()
if l.head != None or l.tail != None or l.current != None:
comment("FAIL -> " + test_name +"\n clear() no actualiza correctamente head, tail o current")
grade(0)
else:
if l.size != 0:
comment("FAIL -> " + test_name +"\nclear() no actualiza correctamente el size de la lista")
grade(0)
else:
comment("OK -> " + test_name)
grade(points['ll_1e_clear'])
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)