Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Created December 22, 2011 07:03
Show Gist options
  • Save shanemhansen/1509312 to your computer and use it in GitHub Desktop.
Save shanemhansen/1509312 to your computer and use it in GitHub Desktop.
install(Word,none) ->
{Word,1,none,none};
install(Word,Tree) when Word<element(1,Tree) ->
{OtherWord,Count,Left,Right}=Tree,
{
OtherWord,
Count,
install(Word,Left),
Right
};
install(Word,Tree) when Word>element(1,Tree) ->
{OtherWord,Count,Left,Right}=Tree,
{
OtherWord,
Count,
Left,
install(Word,Right)
};
install(Word,Tree) when Word =:= element(1,Tree) ->
{_,Count,Left,Right}=Tree,
{
Word,
Count+1,
Left,
Right
}
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment