<gh_stars>0
from node import*
#Class that store the nodes and create a link list
class LinkList(object):
	"""docstring for ClassName"""
	def __init__(self):
		
		self.head=None
	def insert(self,newNode):
		#initially list is empty so our head is empty
		if self.head is None:
			self.head=newNode
		else:
			#head->a->b->None but this will fail while inserting third node
			#If we insert third node then head is not None and head.next=a so it become head->c  
			#which is not the link list 
			#self.head.next=newNode

			#So we need tho check if the node value point to the None then we insert 
			#but for this we need to linearly traverse until will find the node that pointing None 
			#lets Asume our last node is head
			lastNode=self.head
			while True:
				if lastNode.next is None:
					break
				else:
					#lastNode->head->a->b until lastNode.next=None
					lastNode=lastNode.next

			lastNode.next=newNode
	def insertBegining(self,newNode):
		previousHead=self.head
		self.head=newNode
		self.head.next=previousHead

	def insertBetweenNode(self,newNode,position):
		#Before inserting the link list is like a->b->c 
		#We need to insert bb at pos 2 that means a->b->new_node->c  
		currentNode=self.head #current is a
		current_position=0 # 0->1 ->2
		while True:
			if current_position==position:
				previous_node.next=newNode
				newNode.next=currentNode
				break
			previous_node=currentNode
			currentNode=currentNode.next
			current_position+=1


	def traverseList(self):
		#head->a->b->c->None
		currentNode=self.head

		#then current node will go forward until None

		while True:
			if currentNode is None:
				break
			print(currentNode.data)
			currentNode	=currentNode.next
		print(" ")	
	

#To delete node form end we need to travers end of the list checking last node.next is None
#We have to track the previous node because if we delete last node previous node that was pointing to last node now will point to None

	def deleteEndNode(self):

		currentNode=self.head

		while True:
		 	if currentNode.next is None:
		 		previous_node.next=None
		 		break
		 	previous_node=currentNode
		 	currentNode=currentNode.next

#To delete node form end we need to travers to the delete position
#We have to track the previous node because if we delete node of that position was  previous node will point to next of the deleted node 
	def deleteBetweenNode(self,position):

		currentNode=self.head
		current_position=0

		while True:
		 	if current_position==position:
		 		previous_node.next=currentNode.next
		 		break
		 	previous_node=currentNode
		 	currentNode=currentNode.next
		 	current_position=current_position+1	 	


	def mergeList(self,mergeList,firstList,secodList):

		#We need to start traversing from head of the list
		currentFirstnode=firstList.head
		currentSecondnode=secodList.head
		while True:

			if currentFirstnode is None:
				#If first list to the end but 2nd list is still to traverse we add all remaining node to the list and end the loop
				mergeList.insert(currentSecondnode)
				break
			if currentSecondnode is None:
				#If second list to the end but 1st list is stil to traverse we add all remaining node to the list
				mergeList.insert(currentFirstnode)
			if currentFirstnode.data < currentSecondnode.data:
				#Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None
				#But for traversing the list we need to save the current node in a temp variable 
				currentFirstnodeNext=currentFirstnode.next
				currentFirstnode.next=None
				mergeList.insert(currentFirstnode)
				currentFirstnode=currentFirstnodeNext
			else:

				#Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None
				#But for traversing the list we need to save the current node in a temp variable 
				currentSecondnodeNext=currentSecondnode.next
				currentSecondnode.next=None
				mergeList.insert(currentSecondnode)
				currentSecondnode=currentSecondnodeNext
from node import*
#Class that store the nodes and create a link list
class LinkList(object):
	"""docstring for ClassName"""
	def __init__(self):
		
		self.head=None
	def insert(self,newNode):
		#initially list is empty so our head is empty
		if self.head is None:
			self.head=newNode
		else:
			#head->a->b->None but this will fail while inserting third node
			#If we insert third node then head is not None and head.next=a so it become head->c  
			#which is not the link list 
			#self.head.next=newNode

			#So we need tho check if the node value point to the None then we insert 
			#but for this we need to linearly traverse until will find the node that pointing None 
			#lets Asume our last node is head
			lastNode=self.head
			while True:
				if lastNode.next is None:
					break
				else:
					#lastNode->head->a->b until lastNode.next=None
					lastNode=lastNode.next

			lastNode.next=newNode
	def insertBegining(self,newNode):
		previousHead=self.head
		self.head=newNode
		self.head.next=previousHead

	def insertBetweenNode(self,newNode,position):
		#Before inserting the link list is like a->b->c 
		#We need to insert bb at pos 2 that means a->b->new_node->c  
		currentNode=self.head #current is a
		current_position=0 # 0->1 ->2
		while True:
			if current_position==position:
				previous_node.next=newNode
				newNode.next=currentNode
				break
			previous_node=currentNode
			currentNode=currentNode.next
			current_position+=1


	def traverseList(self):
		#head->a->b->c->None
		currentNode=self.head

		#then current node will go forward until None

		while True:
			if currentNode is None:
				break
			print(currentNode.data)
			currentNode	=currentNode.next
		print(" ")	
	

#To delete node form end we need to travers end of the list checking last node.next is None
#We have to track the previous node because if we delete last node previous node that was pointing to last node now will point to None

	def deleteEndNode(self):

		currentNode=self.head

		while True:
		 	if currentNode.next is None:
		 		previous_node.next=None
		 		break
		 	previous_node=currentNode
		 	currentNode=currentNode.next

#To delete node form end we need to travers to the delete position
#We have to track the previous node because if we delete node of that position was  previous node will point to next of the deleted node 
	def deleteBetweenNode(self,position):

		currentNode=self.head
		current_position=0

		while True:
		 	if current_position==position:
		 		previous_node.next=currentNode.next
		 		break
		 	previous_node=currentNode
		 	currentNode=currentNode.next
		 	current_position=current_position+1	 	


	def mergeList(self,mergeList,firstList,secodList):

		#We need to start traversing from head of the list
		currentFirstnode=firstList.head
		currentSecondnode=secodList.head
		while True:

			if currentFirstnode is None:
				#If first list to the end but 2nd list is still to traverse we add all remaining node to the list and end the loop
				mergeList.insert(currentSecondnode)
				break
			if currentSecondnode is None:
				#If second list to the end but 1st list is stil to traverse we add all remaining node to the list
				mergeList.insert(currentFirstnode)
			if currentFirstnode.data < currentSecondnode.data:
				#Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None
				#But for traversing the list we need to save the current node in a temp variable 
				currentFirstnodeNext=currentFirstnode.next
				currentFirstnode.next=None
				mergeList.insert(currentFirstnode)
				currentFirstnode=currentFirstnodeNext
			else:

				#Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None
				#But for traversing the list we need to save the current node in a temp variable 
				currentSecondnodeNext=currentSecondnode.next
				currentSecondnode.next=None
				mergeList.insert(currentSecondnode)
				currentSecondnode=currentSecondnodeNext
#Class that store the nodes and create a link list docstring for ClassName #initially list is empty so our head is empty #head->a->b->None but this will fail while inserting third node #If we insert third node then head is not None and head.next=a so it become head->c #which is not the link list #self.head.next=newNode #So we need tho check if the node value point to the None then we insert #but for this we need to linearly traverse until will find the node that pointing None #lets Asume our last node is head #lastNode->head->a->b until lastNode.next=None #Before inserting the link list is like a->b->c #We need to insert bb at pos 2 that means a->b->new_node->c #current is a # 0->1 ->2 #head->a->b->c->None #then current node will go forward until None #To delete node form end we need to travers end of the list checking last node.next is None #We have to track the previous node because if we delete last node previous node that was pointing to last node now will point to None #To delete node form end we need to travers to the delete position #We have to track the previous node because if we delete node of that position was  previous node will point to next of the deleted node #We need to start traversing from head of the list #If first list to the end but 2nd list is still to traverse we add all remaining node to the list and end the loop #If second list to the end but 1st list is stil to traverse we add all remaining node to the list #Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None #But for traversing the list we need to save the current node in a temp variable #Our new list last inserted item need to be point to None so we need to convert currentNode which is pointing to the next node to point None #But for traversing the list we need to save the current node in a temp variable