Method: Containers::RubyDeque#push_front
- Defined in:
- lib/containers/deque.rb
#push_front(obj) ⇒ Object
Adds an object at the front of the Deque.
d = Containers::Deque.new([1, 2, 3])
d.push_front(0)
d.pop_front #=> 0
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/containers/deque.rb', line 69 def push_front(obj) node = Node.new(nil, nil, obj) if @front node.right = @front @front.left = node @front = node else @front = @back = node end @size += 1 obj end |