class LifoStack

Public Instance Methods

clear() click to toggle source
# File lib/stack.rb, line 24
def clear
        while self.peek
                pop
        end
end
empty() click to toggle source
# File lib/stack.rb, line 38
def empty
        if @top.nil?
                puts "Stack is empty"
        else
                puts "Stack is full"
        end
end
full() click to toggle source
# File lib/stack.rb, line 30
def full
        if @top
                puts "Stack is full"
        else
                puts "Stack is empty"
        end
end
peek() click to toggle source
# File lib/stack.rb, line 16
def peek
        if @top == 0
                puts "Peek is empty"
        else
                puts @top
        end
end
pop() click to toggle source
# File lib/stack.rb, line 46
def pop
        if not @top
                return nil
        else
                tmp = @top
                @top = @top.node
                tmp.element
        end
end
push(element) click to toggle source
# File lib/stack.rb, line 12
def push(element)
        @top = Node.new(element, @top)
end