本文整理匯總了Python中LinkedList.LinkedList.__str__方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.__str__方法的具體用法?Python LinkedList.__str__怎麽用?Python LinkedList.__str__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.__str__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testLinkedList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import __str__ [as 別名]
def testLinkedList():
ll = LinkedList()
while True:
print ("Choose operation: ")
print (" 1 - Add\n",
"2 - Remove\n",
"3 - Search\n",
"4 - Size\n",
"5 - Exit\n")
choice = input()
if choice == '1':
ll = addll(ll)
ll.__str__()
elif choice == '2':
ll == removell(ll)
ll.__str__()
elif choice == '3':
searchKey(ll)
ll.__str__()
elif choice == '4':
size(ll)
ll.__str__()
elif choice == '5':
break
else:
print ("BAD Choice! Choose from 1 to 4 numbers")
示例2: __init__
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import __str__ [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
示例3: comment
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import __str__ [as 別名]
comment("OK -> " + test_name)
grade(points['ll_1e_getsize'])
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)
# Check one element list - __str__()
try:
test_name = 'LinkedList con un elemento: __str__'
l = LinkedList()
l.insertAfter(17)
if type(str(l)) == types.StringType and not l.__str__().count('17') != 1:
comment("OK -> " + test_name)
grade(points['ll_1e_str'])
else:
comment("FAIL -> " + test_name +"\n __str__ debe devolver una lista de caracteres (string) con los elementos de la lista")
grade(0)
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)
# Check one element list - remove()
try:
示例4: LinkedList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import __str__ [as 別名]
from LinkedList import LinkedList
# Test cases for LinkedList
linklist = LinkedList()
linklist2 = LinkedList()
linklist.add(1)
print(linklist.__str__())
linklist.add(2)
print(linklist.__str__())
linklist.add(3)
print(linklist.__str__())
linklist.add(4)
print(linklist.__str__())
linklist.remove(2)
print(linklist.__str__())
linklist.remove(1)
linklist.remove(6)
print(linklist.contains(1))
print(linklist.__str__())
print(linklist.size)