Skip to content

Commit 2d3fad6

Browse files
committed
Implementa la pila
1 parent c08eb07 commit 2d3fad6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

stack.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Stack
2+
def push(e)
3+
@top = Node.new(e, @top)
4+
end
5+
6+
def pop
7+
return nil unless @top
8+
old_top = @top
9+
@top = @top.next_node
10+
old_top.element
11+
end
12+
end
13+
14+
class Node
15+
attr_reader :element, :next_node
16+
17+
def initialize(element, next_node)
18+
@element = element
19+
@next_node = next_node
20+
end
21+
end

0 commit comments

Comments
 (0)