Skip to content

Instantly share code, notes, and snippets.

@kirkconnell
Created May 6, 2013 23:37
Show Gist options
  • Save kirkconnell/5529175 to your computer and use it in GitHub Desktop.
Save kirkconnell/5529175 to your computer and use it in GitHub Desktop.
Red/Black Tree implementation in GO
1- Write the tree.Add(int) function
2- Write a red black tree validator
- check if root is black
- check if the number of black nodes from the root to every nil is the same
- check that there are no two consecutive red nodes
3- Write the tree.Contains(int) function
@oscardelben
Copy link

func PrintTree(node *Node) {
  if node == nil {
    fmt.Print("nil ")
    return
  }
  fmt.Print("(")
  fmt.Print(node.value)
  fmt.Print(" ")
  PrintTree(node.left)
  PrintTree(node.right)
  fmt.Print(")")
  fmt.Print(" ")


}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment