SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def delete(self, v):
  2.         '''
  3.         Removes the value `v` from the tree and returns the new (updated) tree.
  4.         If `v` is a non-member, the same tree is returned without modification.
  5.         '''
  6.  
  7.         if self.is_empty():
  8.             return self
  9.         if v < self.value():
  10.             return self.cons(self.lc().delete(v),self.rc())
  11.         if v > self.value():
  12.             return self.cons(self.lc(),self.rc().delete(v))
  13.         if v is self.value():
  14.             return self.Unlink(v)
  15.         else:
  16.             return self
  17.  
  18.  
  19.     def Unlink(self,v):
  20.         if self.lc().value() is None and self.rc().value() is None:
  21.             return self.set_value(None)
  22.  
  23.         if self.lc().value() is None:
  24.             return self.rc()
  25.  
  26.         elif self.rc().value() is None:
  27.             return self.lc()
  28.  
  29.         else:
  30.             if self.rc().height() > self.lc().height():
  31.                 temp = self.rc().Minimum()
  32.                 self.set_value(temp)
  33.                 return self.cons(self.lc(),self.rc().delete(temp))
  34.             else:
  35.                 temp = self.lc().Maximum()
  36.                 self.set_value(temp)
  37.                 return self.cons(self.lc().delete(temp),self.rc())
  38.  
  39.  
  40.     def Minimum(self):
  41.         if self.lc().value() is not None:
  42.             return self.lc().value().Minimum()
  43.         else:
  44.             return self.value()
  45.  
  46.     def Maximum(self):
  47.         if self.rc().value() is not None:
  48.             return self.rc().value().Maximum()
  49.         else:
  50.             return self.value()
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