本文整理匯總了Python中LinkedList.LinkedList.removeAt方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.removeAt方法的具體用法?Python LinkedList.removeAt怎麽用?Python LinkedList.removeAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.removeAt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import removeAt [as 別名]
class Queue:
def __init__(self):
self.__elements = LinkedList()
# Adds an element to this queue
def enqueue(self, e):
self.__elements.add(e)
# Removes an element from this queue
def dequeue(self):
if self.getSize() == 0:
return None
else:
return self.__elements.removeAt(0)
# Return the size of the queue
def getSize(self):
return self.__elements.getSize()
# Returns a string representation of the queue
def __str__(self):
return self.__elements.__str__()
# Return true if queue is empty
def isEmpty(self):
return self.getSize() == 0
示例2: print
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import removeAt [as 別名]
list.add("America") # Add it to the list
print("(1)", list)
list.insert(0, "Canada") # Add it to the beginning of the list
print("(2)", list)
list.add("Russia") # Add it to the end of the list
print("(3)", list)
list.addLast("France") # Add it to the end of the list
print("(4)", list)
list.insert(2, "Germany") # Add it to the list at index 2
print("(5)", list)
list.insert(5, "Norway") # Add it to the list at index 5
print("(6)", list)
list.insert(0, "Poland") # Same as list.addFirst("Poland")
print("(7)", list)
# Remove elements from the list
list.removeAt(0) # Remove the element at index 0
print("(8)", list)
list.removeAt(2) # Remove the element at index 2
print("(9)", list)
list.removeAt(list.getSize() - 1) # Remove the last element
print("(10)", list)