def enqueueFront(self,val): if not self.__head: self.__tail=self.__head=Node(val) else: temp=Node(val) temp.Next=self.__head self.__head.Prev=temp self.__head=temp
def enqueueBack(self,val): if not self.__tail: self.__tail=self.__head=Node(val) else: temp=Node(val) self.__tail.Next=temp temp.Prev=self.__tail self.__tail=temp
def insert(self,x): if self.__head: cur=self.__head while cur.Next: cur=cur.Next temp=Node(x) temp.Prev,cur.Next,self.__tail=cur,temp,temp else: self.__tail=self.__head=Node(x) DL.__size+=1
def insertInOrder(self,x): if self.__head and self.__tail: pre,cur=None,self.__head while cur.Next and cur.val<=x: pre,cur=cur,cur.Next if cur==self.__head: temp=Node(x) temp.Next=self.__head self.__head.Prev=temp self.__head=temp elif cur.Next==None: cur.Next=Node(x) cur.Next.Prev=cur self.__tail=cur.Next else: pre.Next=Node(x) pre.Next.Prev=pre pre.Next.Next=cur cur.Prev=pre.Next else: self.__tail=self.__head=Node(x) DL.__size+=1