lib/ruby_algorithms/containers/stack.rb
# Push nodes onto the stack by first checking if there is anything on the stack.
# If not, push create a new node and add it to @top. Otherwise, store the
# current @top in a temp variable then override @top with the new node. Finally,
# set the next attibute to point to the old @top.
Push nodes onto the stack by first checking if there is anything on the stack.
If not, push create a new node and add it to @top. Otherwise, store the
current @top in a temp variable then override @top with the new node. Finally,
set the next attibute to point to the old @top.
Push nodes onto the stack by first checking if there is anything on the stack . If not push create a new node and add it to @top . Otherwise store the current @top in a temp variable then override @top with the new node . Finally set the next attibute to point to the old @top .
def push(obj)
    if @top.nil?
      @top = Node.new(obj)
    else
      old_top = @top
      @top = Node.new(obj)
      @top.next = old_top
    end
  end
def push ( obj ) if @top . nil? @top = Node . new ( obj ) else old_top = @top @top = Node . new ( obj ) @top . next = old_top end end
Push nodes onto the stack by first checking if there is anything on the stack.
Push nodes onto the stack by first checking if there is anything on the stack .
obj