Skip to content

Instantly share code, notes, and snippets.

@MiriamNeubauer
Forked from rsofaer/postfixhints.rb
Created December 3, 2013 23:41
Show Gist options
  • Select an option

  • Save MiriamNeubauer/7779771 to your computer and use it in GitHub Desktop.

Select an option

Save MiriamNeubauer/7779771 to your computer and use it in GitHub Desktop.
class TreeNode
attr_accessor :val, :left, :right
def initialize(v)
@val = v
end
def leaf?
# A node is a leaf if it has no children.
end
end
def numeric?(str)
true if Float(str) rescue false
end
def parse_postfix_expression(exp)
# Split our arithmetic expression at the whitespaces.
# Since we are parsing postfix, the root node will always be the last token.
end
def get_next_node(tokens)
# The next token will be the root of the tree we are building.
# If we are a number node, we are a leaf, so skip this.
# The second token will be the beginning of the right subtree.
# After the left subtree will come the left subtree.
end
data = File.read("data").split("\n").map {|l| parse_postfix_expression(l)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment