本文整理汇总了Python中MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList.appendToListUsingTail方法的典型用法代码示例。如果您正苦于以下问题:Python SinglyLinkedList.appendToListUsingTail方法的具体用法?Python SinglyLinkedList.appendToListUsingTail怎么用?Python SinglyLinkedList.appendToListUsingTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.appendToListUsingTail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append_when_list_is_empty
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import appendToListUsingTail [as 别名]
def test_append_when_list_is_empty(self):
singlyLinkedListObject = SinglyLinkedList()
inputVal = 10
singlyLinkedListObject.appendToListUsingTail(inputVal)
outputList = singlyLinkedListObject.returnLinkedListAsList()
outputVal = outputList[0]
self.assertTrue(inputVal == outputVal, "Expected a tail value of: %s, Got: %s" %(inputVal, outputVal))
示例2: test_append_when_list_has_at_least_one_element
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import appendToListUsingTail [as 别名]
def test_append_when_list_has_at_least_one_element(self):
singlyLinkedListObject = SinglyLinkedList()
inputList = range(10)
singlyLinkedListObject.populate(inputList)
inputVal = 10
singlyLinkedListObject.appendToListUsingTail(inputVal)
self.assertTrue(singlyLinkedListObject.tail.data == inputVal, "Expected Tail data: %s, Got: %s" %(inputVal, singlyLinkedListObject.tail.data))
outputList = singlyLinkedListObject.returnLinkedListAsList()
outputVal = outputList[-1]
self.assertTrue(inputVal == outputVal, "Expected tail value: %s, Got: %s" %(inputVal, outputVal))
示例3: test_changing_list_length_during_append_operation
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import appendToListUsingTail [as 别名]
def test_changing_list_length_during_append_operation(self):
singlyLinkedListObject = SinglyLinkedList()
expectedLength = 0
actualLength = len(singlyLinkedListObject)
self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
inputList = range(10)
for data in inputList:
singlyLinkedListObject.appendToListUsingTail(data)
actualLength = len(singlyLinkedListObject)
expectedLength += 1 # Because a new element has been added to the list.
self.assertTrue(expectedLength == actualLength, "Expected length: %s, Actual Length: %s" %(expectedLength, actualLength))
示例4: partitionLinkedListBasedOnAGivenNumber_createNewList
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import appendToListUsingTail [as 别名]
def partitionLinkedListBasedOnAGivenNumber_createNewList(self, givenNumber):
firstList = SinglyLinkedList()
secondList = SinglyLinkedList()
for data in self.givenSinglyLinkedList:
if data < givenNumber:
firstList.appendToListUsingTail(data)
else:
secondList.appendToListUsingTail(data)
# print firstList.returnLinkedListAsList()
# print secondList.returnLinkedListAsList()
if firstList.isListEmpty():
return secondList
elif secondList.isListEmpty():
return firstList
else:
firstList.tail.nextPointer = secondList.head # Could be the other way round as well (secondList.tail.nextPointer = firstList.head ), but since it wasn't asked in the question, I've chosen the first option. In a real interview, I would ask the interviewer
return firstList
示例5: partitionLinkedListBasedOnAGivenNumber_DontCreateNewList
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import appendToListUsingTail [as 别名]
def partitionLinkedListBasedOnAGivenNumber_DontCreateNewList(self, givenNumber):
# check head against given number. Move to appropriate list. advance head to next. delete previous head
firstList = SinglyLinkedList()
secondList = SinglyLinkedList()
for data in self.givenSinglyLinkedList:
if data < givenNumber:
firstList.appendToListUsingTail(data)
else:
secondList.appendToListUsingTail(data)
self.givenSinglyLinkedList.deleteHead() # Deleting head as the data is already under the relevant - firstList or secondList
if firstList.isListEmpty():
return secondList
elif secondList.isListEmpty():
return firstList
else:
firstList.tail.nextPointer = secondList.head # Could be the other way round as well (secondList.tail.nextPointer = firstList.head ), but since it wasn't asked in the question, I've chosen the first option. In a real interview, I would ask the interviewer
return firstList