Class: DSA::ArrayStack
- Inherits:
-
Object
- Object
- DSA::ArrayStack
- Defined in:
- lib/DSA/stack_and_queue.rb
Overview
The stack data structure Delegate the job to ruby Array, no need to worry about its growing and shrinking.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ ArrayStack
constructor
A new instance of ArrayStack.
- #length ⇒ Object
- #pop ⇒ Object
- #push(e) ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize ⇒ ArrayStack
Returns a new instance of ArrayStack.
7 8 9 |
# File 'lib/DSA/stack_and_queue.rb', line 7 def initialize @data = Array.new end |
Instance Method Details
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/DSA/stack_and_queue.rb', line 23 def empty? @data.empty? end |
#length ⇒ Object
27 28 29 |
# File 'lib/DSA/stack_and_queue.rb', line 27 def length @data.length end |
#pop ⇒ Object
15 16 17 |
# File 'lib/DSA/stack_and_queue.rb', line 15 def pop @data.pop end |
#push(e) ⇒ Object
11 12 13 |
# File 'lib/DSA/stack_and_queue.rb', line 11 def push(e) @data.push e end |
#top ⇒ Object
19 20 21 |
# File 'lib/DSA/stack_and_queue.rb', line 19 def top @data.last end |