class Stack
This is a implementation of stack using array
Attributes
length[R]
Public Class Methods
new()
click to toggle source
# File lib/data_struct/stack.rb, line 6 def initialize @stack = [] @length = 0 end
Public Instance Methods
empty?()
click to toggle source
# File lib/data_struct/stack.rb, line 25 def empty? @stack.empty? end
pop()
click to toggle source
# File lib/data_struct/stack.rb, line 16 def pop de_length @stack.pop end
push(val)
click to toggle source
# File lib/data_struct/stack.rb, line 11 def push(val) in_length @stack.push val end
to_a()
click to toggle source
# File lib/data_struct/stack.rb, line 29 def to_a @stack end
top()
click to toggle source
# File lib/data_struct/stack.rb, line 21 def top @stack.last end
Private Instance Methods
de_length()
click to toggle source
# File lib/data_struct/stack.rb, line 39 def de_length @length -= 1 end
in_length()
click to toggle source
# File lib/data_struct/stack.rb, line 35 def in_length @length += 1 end