Exemplo n.º 1
0
	def insertInOrder(self,x):
		if self.__head:
			pre,cur=None,self.__head
			while cur.Next!=self.__head and x>cur.val:
				pre,cur=cur,cur.Next
			temp=Node(x)
			if not pre:
			# ^^ conditional check takes care of the cases where the insertion has to be made at the beginning or end
				temp.Next=cur
				self.__head=temp
			else:
				temp.Next=pre.Next
				pre.Next=temp
		else:
			self.__head=Node(x)					
		CL.__size+=1
Exemplo n.º 2
0
 def Insert(self,index=None,element=None):
     self.__locationNode(index)
     node=Node(element)
     #list have no node
     if(self.__size==0):
         self.__current=self.__end=self.__head=node
     else:            
         #new node's next node is current's next
         node.Next=self.__current.Next
         #new node's previous node is current node
         self.__current.Next=node
         #insert at end of list,End need move on
         if(self.__current==self.__end):
             self.__end=self.__end.Next
     #increases size
     self.__size+=1        
Exemplo n.º 3
0
	def insertInOrder(self,x):
		if self.__head:
			pre,cur=None,self.__head
			while cur.Next and cur.val<=x:
				pre,cur=cur,cur.Next
			if cur==self.__head and pre==None:
				temp=Node(x)
				temp.Next=self.__head
				self.__head=temp
			elif cur.Next==None and pre:
				pre.Next=Node(x)
			else:
				pre.Next,pre.Next.Next=Node(x),cur
		else:
			self.__head=Node(x)
		SL.__size+=1