当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.insertNode方法代码示例

本文整理汇总了Python中linkedlist.LinkedList.insertNode方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.insertNode方法的具体用法?Python LinkedList.insertNode怎么用?Python LinkedList.insertNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linkedlist.LinkedList的用法示例。


在下文中一共展示了LinkedList.insertNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createDepthLinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
def createDepthLinkedList():
	nodesAtDepth = LinkedList()
	nodesAtDepth.insertNode(tree.root.data)
	q=[]
	q.append(tree.root)
	
	depthLinkedList =[nodesAtDepth]
	condition = True
	while condition:
		children = []
		while (q):
			node= q.pop(0)
			if(node.left != None):
				children.append(node.left)
			if(node.right != None):
				children.append(node.right)
		condition = True if children else False
		if(condition):
			nodesAtDepth = LinkedList()
			for node in children:
				nodesAtDepth.insertNode(node.data)
			depthLinkedList.append(nodesAtDepth)
			q.extend(children)
	for linkedlist in depthLinkedList:
		 linkedlist.display()
开发者ID:nirmalvp,项目名称:algos,代码行数:27,代码来源:linkedlistdepth.py

示例2: scramble

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
def scramble(self):
	fast=self.first
	slow=self.first

	while(fast!=None):
		fast=fast.next.next
		slow=slow.next

	fast=self.first

	scrambledList=LinkedList()
	while(slow!=None):
		scrambledList.insertNode(fast.data)
		scrambledList.insertNode(slow.data)
		fast = fast.next
		slow = slow.next
	return scrambledList
开发者ID:nirmalvp,项目名称:algos,代码行数:19,代码来源:linkedlistscramble.py

示例3: LinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
from linkedlist import LinkedList

myList= LinkedList()
myList.insertNode(1)
myList.insertNode(2)
myList.insertNode(3)
myList.insertNode(4)
myList.insertNode(5)
myList.insertNode(11)
myList.insertNode(12)
myList.insertNode(13)
myList.insertNode(14)
myList.insertNode(15)

def scramble(self):
	fast=self.first
	slow=self.first

	while(fast!=None):
		fast=fast.next.next
		slow=slow.next

	fast=self.first

	scrambledList=LinkedList()
	while(slow!=None):
		scrambledList.insertNode(fast.data)
		scrambledList.insertNode(slow.data)
		fast = fast.next
		slow = slow.next
	return scrambledList
开发者ID:nirmalvp,项目名称:algos,代码行数:33,代码来源:linkedlistscramble.py

示例4: LinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
from linkedlist import LinkedList

myList = LinkedList()
for i in range(1,11):
	myList.insertNode(i)

def kthlast(self,k):
	fast = self.first
	slow = self.first
	for i in range(k-1):
		if(fast.next!=None):
			fast=fast.next
		else :
			print "Not enough elements"
			return
	while(fast.next!=None):
		fast=fast.next
		slow= slow.next
	print "kthlast : ",slow.data

LinkedList.kthlast = kthlast

myList.kthlast(3)


开发者ID:nirmalvp,项目名称:algos,代码行数:25,代码来源:linkedlistklast.py

示例5: raw_input

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
from linkedlist import LinkedList

palin = raw_input("Enter palin Strng : ")
myList = LinkedList()
for ch in palin:
	myList.insertNode(ch)


def checkPalindrom(self):
	myStack =[]
	slow = myList.first
	fast = myList.first
	myStack.append(slow.data)

	while(fast!=None and fast.next!=None):
		slow=slow.next
		fast=fast.next.next
		if(fast !=None):
			myStack.append(slow.data)
	
	while (slow != None):
		if(slow.data != myStack.pop()):
			print "Not palin"
			return
		slow=slow.next
	print "Palindrome"

LinkedList.checkPalindrom = checkPalindrom
myList.checkPalindrom()

开发者ID:nirmalvp,项目名称:algos,代码行数:31,代码来源:linkedlistpalin.py

示例6: map

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
from linkedlist import LinkedList, Node
num1 = map(int,raw_input("enter number 1 : "))
num2 = map(int,raw_input("enter number 2 : "))

firstNum = LinkedList()
for x in num1:
	firstNum.insertNode(x)

secondNum = LinkedList()
for x in num2:
	secondNum.insertNode(x)


temp = firstNum.first
firstStack=[]

while(temp!=None):
	firstStack.append(temp.data)
	temp = temp.next

temp = secondNum.first
secondStack=[]

while(temp!=None):
	secondStack.append(temp.data)
	temp = temp.next

def insertFirst(theList,data):
	node = Node(data)
	node.next = theList.first
	theList.first = node
开发者ID:nirmalvp,项目名称:algos,代码行数:33,代码来源:linkedlistorderadd.py

示例7: LinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import insertNode [as 别名]
from linkedlist import LinkedList
from random import randint

myList = LinkedList()

for i in range(10):
	myList.insertNode(randint(0,9))

def partition(self):
	pivot = self.first.data
	start = self.first
	temp = self.first
	while(temp.next!=None):
		if(temp.next.data < pivot):
			nextElement = temp.next.next
			temp.next.next = start
			start = temp.next
			temp.next=nextElement
		else:
			temp = temp.next
	self.first = start

LinkedList.partition = partition
myList.display()
myList.partition()
myList.display()


			

开发者ID:nirmalvp,项目名称:algos,代码行数:28,代码来源:linkedlistpartition.py


注:本文中的linkedlist.LinkedList.insertNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。