Defines a Linked List interface and Abstract Factory. The LinkedList class defines seven public instance methods, and three protected methods. Three attributes were implicitly defined. The size attribute is an integer and represents the list size. The front attribute is the foremost node in the list. The back attribute is the hindmost node in the list.


Add this line to your application's Gemfile:

gem 'linked_list_i', '~> 1.1'

And then execute:

$ bundle

Or install it yourself as:

$ gem install linked_list_i


The interface defines seven public instance methods and three protected methods.

Public Methods

There are seven public instance methods: initialize(node_object = nil), size(), empty?(), front(), back(), insert(pos, data_object), and remove(pos).

iniitialize(node_object = nil)

The constructor. Takes a node object and initializes the list. The node object defaults nil.


Getter method. Gets and returns the list size.


Boolean method. Returns true in the case the list contains zero nodes, and false otherwise.


Getter method. Gets and returns the node the front attribute refers.


Getter method. Gets and returns the node the back attribute refers.

insert(pos, data_object)

Constructs a node, sets the node's data attribute the data_object, and inserts the node in the list at index pos. Pos is an integer and represents the insertion index. data_object is an acceptable data object.


Assigns the front node reference the node proceeding the node at index pos, and assigns the node proceeding the node at index pos's back node the node preceding it. pos is an integer and is the removal index.

Protected Methods

The class protects three methods: swap(ll_object = nil), ==(ll_object), and !=(ll_object).

swap(ll_object = nil)

Swaps self's list and ll_object's list. ll_object is a Linked List object.


Equality operator. Returns true in the case all self's nodes refer the same nodes at each index in ll_object's list. Returns false otherwise. ll_object is a Linked List object.


Inequality operator. Returns true in the case at least one node self contains is a separate node from a node in ll_object's list at the corresponding index. Returns false otherwise. Takes a Linked List object ll_object.


After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the LinkedList project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.