       return left
     }
   }
+  func maximum() -> Candy {
+    if let r = self.R {
+      return r.maximum()
+    }
+    return self
+  }
+  func replace(tree: Candy, with: Candy?) {
+    if tree.value == self.R?.value {
+      self.R = with
+      with?.parent = self.R
+    } else if tree.value == self.L?.value {
+      self.L = with
+      with?.parent = self.L
+    }
+    tree.parent = nil
+  }
   func remove(n: Int) {
-    if self.contains(n) {
-
+    if n < self.value {
+      if let l = self.L {
+        l.remove(n)
+      }
+    } else if n == self.value {
+      self.count -= 1
+    } else {
+      if let r = self.R {
+        r.remove(n)
+      }
     }
   }
 }
-
-var c = Candy(10)
-c.insert(16)
-c.insert(19)
-c.insert(16)
-c.insert(6)
-
-
-print(c.list(59))
-print(c.list(17))

      if let r = self.R {
        r.insert(n)
      } else {
        self.R = Candy(n)
      }
    }
  }

        return l.contains(n)
      }
    } else if n == self.value {
      return self.count > 0
    } else {
      if let r = self.R {
        return r.contains(n)
