本文整理汇总了Python中MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList.isListEmpty方法的典型用法代码示例。如果您正苦于以下问题:Python SinglyLinkedList.isListEmpty方法的具体用法?Python SinglyLinkedList.isListEmpty怎么用?Python SinglyLinkedList.isListEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.isListEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: partitionLinkedListBasedOnAGivenNumber_createNewList
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import isListEmpty [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
示例2: partitionLinkedListBasedOnAGivenNumber_DontCreateNewList
# 需要导入模块: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList import SinglyLinkedList [as 别名]
# 或者: from MyLibrary.LinkedLists.SinglyLinkedLists.SinglyLinkedList.SinglyLinkedList import isListEmpty [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