Class: RubyDataStructures::FifoStack

Inherits:
StackAsArray show all
Defined in:
lib/RubyDataStructures/fifo_stack.rb

Instance Attribute Summary

Attributes inherited from StackAsArray

#length, #top

Instance Method Summary collapse

Methods inherited from StackAsArray

#each, #empty?, #first, #full?, #initialize, #last, #pop, #reset, #singleton?, #size

Constructor Details

This class inherits a constructor from RubyDataStructures::StackAsArray

Instance Method Details

#push(element) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/RubyDataStructures/fifo_stack.rb', line 2

def push(element)
  
  if self.full?
    @array.shift
    @top -= 1
  end      

  if self.empty?
    @top = 0
  else
    @top = @top + 1
  end

  @array[@top] = element
end