0.02
Low commit activity in last 3 years
No release in over a year
Ruby implementation of Doubly Linked List, following some Ruby idioms.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.0, < 3.0
~> 1.5, >= 1.5.0
>= 5.0, <= 6.0
>= 12.3.3
 Project Readme

Code Climate Build Status Gem Version Coverage Status

LinkedList

Ruby implementation of Doubly Linked List, following some Ruby idioms.

Installation

Add this line to your application's Gemfile:

gem 'linked-list'

And then execute:

$ bundle

Or install it yourself as:

$ gem install linked-list

Usage

object = Object.new # could be anything
list = LinkedList::List.new

list.push(object)
list << object # same as `push`

list.unshift(object)

list.pop
list.shift

list.insert(object, before: object)
list.insert(object, before: ->(n) { n == 'foo' })

list.insert(object, after: object)
list.insert(object, after: ->(n) { n == 'foo' })

list.insert_before(object, node)
list.insert_after(object, node)

list.reverse
list.reverse!

list.delete(object)
list.delete { |n| n == 'foo' }

list.delete_all(object)
list.delete_all { |n| n == 'foo' }

list.each  # Enumerator object
list.each { |e| puts e }

list.reverse_each # Enumerator object
list.reverse_each { |e| puts e }

list.reverse_each_node # Enumerator object
list.reverse_each_node { |node| puts node.data }

list.first # head of the list
list.last # tail of the list

list.length
list.size # same as `length`

list.to_a

Another way to instantiate List or Node is to use conversion functions. First, include LinkedList::Conversions module to your class

class Foo
  include LinkedList::Conversions
end

Now anywhere in your class you can use the following methods

Node(object)           # will return new `Node` object
List(object)           # will return new `List` object with one `Node` object
List([object, object]) # will return new `List` object with two `Node` objects

Please see LinkedList::List, LinkedList::Node, and LinkedList::Conversions for details.

Tests

Run test with

$ rake

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request