red-black tree Clear() method

pull/1/head
Emir Pasic 9 years ago
parent a2b057ed41
commit fae29a732d

@ -164,7 +164,7 @@ func (tree *Tree) Keys() []interface{} {
return keys
}
// Returns all values in-order based on the key
// Returns all values in-order based on the key.
func (tree *Tree) Values() []interface{} {
values := make([]interface{}, tree.size)
for i, node := range tree.inOrder() {
@ -173,6 +173,12 @@ func (tree *Tree) Values() []interface{} {
return values
}
// Removes all nodes from the tree.
func (tree *Tree) Clear() {
tree.root = nil
tree.size = 0
}
func (tree *Tree) String() string {
str := "RedBlackTree\n"
if !tree.Empty() {

@ -141,4 +141,13 @@ func TestRedBlackTree(t *testing.T) {
t.Errorf("Got %v expected %v", actualValue, true)
}
tree.Put(1, "a")
tree.Put(2, "b")
tree.Clear()
// Test Empty()
if actualValue := tree.Empty(); actualValue != true {
t.Errorf("Got %v expected %v", actualValue, true)
}
}

Loading…
Cancel
Save