daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class Node:
  3.     def __init__(self,prev,data,nextto):
  4.         self.prev = prev
  5.         self.data = data
  6.         self.next = nextto
  7.  
  8. class DLL:
  9.    
  10.     def __init__(self):
  11.         self.head = None
  12.         self.tail = None
  13.         self.curr = None
  14.        
  15.  
  16.     def add_to_front(self,value):
  17.         if self.head == None:
  18.             self.head = Node(None,value,self.tail)
  19.         else:
  20.             self.head = Node(None,value,self.head)
  21.        
  22.     def add_to_back(self,value):
  23.         if self.head == None:
  24.             self.head = Node(None,value,self.tail)
  25.         elif self.tail == None and self.head.next == self.tail:
  26.             self.tail = Node(self.head,value,None)
  27.             self.head = Node(None,self.head.data,self.tail)
  28.         else:
  29.            
  30.             self.tail.prev = self.tail
  31.             self.tail = Node(self.tail.prev,value,None)
  32.             self.tail.prev.next = self.tail
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top