Method: RubyDataStructures::StackAsArray#push
- Defined in:
- lib/RubyDataStructures/stack_as_array.rb
#push(element) ⇒ Object
Pushes an element element into the stack
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/RubyDataStructures/stack_as_array.rb', line 26 def push(element) raise "Stack Overflow - The stack is full" if self.full? if self.empty? @top = 0 else @top = @top + 1 end @array[@top] = element end |