Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cosmetic

  • Loading branch information...
commit 2f55f1e8ddade5760726a5980da0bb38cbc64381 1 parent cad4f5c
@nahi authored
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/avl_tree.rb
View
16 lib/avl_tree.rb
@@ -25,14 +25,17 @@ def each(&block)
# intentionally blank
end
+ # returns new_root
def store(key, value)
Node.new(key, value)
end
+ # returns value
def retrieve(key)
UNDEFINED
end
+ # returns [deleted_node, new_root]
def delete(key)
[self, self]
end
@@ -134,15 +137,13 @@ def delete(key)
case key <=> @key
when -1
deleted, @left = @left.delete(key)
- root = self
+ [deleted, self.rotate]
when 0
- deleted = self
- root = delete_self
+ [self, delete_self.rotate]
when 1
deleted, @right = @right.delete(key)
- root = self
+ [deleted, self.rotate]
end
- [deleted, root.rotate]
end
def delete_min
@@ -234,16 +235,15 @@ def rotate
def delete_self
if @left.empty? and @right.empty?
- EMPTY
+ deleted = EMPTY
elsif @right.height < @left.height
deleted, new_left = @left.delete_max
deleted.left, deleted.right = new_left, @right
- deleted
else
deleted, new_right = @right.delete_min
deleted.left, deleted.right = @left, new_right
- deleted
end
+ deleted
end
def rotate_RR
Please sign in to comment.
Something went wrong with that request. Please try again.