Class: LifoStack
- Inherits:
-
Object
- Object
- LifoStack
- Defined in:
- lib/stack.rb
Defined Under Namespace
Classes: Node
Instance Method Summary collapse
Instance Method Details
#clear ⇒ Object
24 25 26 27 28 |
# File 'lib/stack.rb', line 24 def clear while self.peek pop end end |
#empty ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/stack.rb', line 38 def empty if @top.nil? puts "Stack is empty" else puts "Stack is full" end end |
#full ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/stack.rb', line 30 def full if @top puts "Stack is full" else puts "Stack is empty" end end |
#peek ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/stack.rb', line 16 def peek if @top == 0 puts "Peek is empty" else puts @top end end |
#pop ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/stack.rb', line 46 def pop if not @top return nil else tmp = @top @top = @top.node tmp.element end end |