This project creates a Ruby LinkedList class to mimic the behavior of the linked list data structures found in other programming languages. This project is part of the The Odin Project curriculum.
A linked list is a linear collection of data elements, where each element contains some sort of data or value and a pointer to the next element in the list. In the list, "head" refers to the first element, and "tail" refers to the last element.
[ NODE (head) ] -> [ NODE ] -> [ NODE ] -> [ NODE (tail) ] -> nil
Along with the Node class, the LinkedList class contains the following functionality:
#append
adds a new node to the end of the list.#prepend
adds a new node to the start of the list.#size
returns the total number of nodes in the list.#head
returns the first node in the list.#tail
returns the last node in the list.#at(index)
returns the node at the given index.#pop
removes the last element from the list.#contains?(value)
returns true if the passed in value is in the list and returns false otherwise.#find(value)
returns the index of the node containing the given value ornil
if the value is not found.#to_s
represents the LinkedList object as a string so that they can be printed out and previewed in the console. The format of this string is, "( data ) -> ( data ) -> ( data ) -> nil".
- Ruby 2.5.3
- RSpec 3.8
- Fork this repository on GitHub.
- Clone your forked reposity onto your local computer.
- To run the tests,
cd
into the main directory and then runrspec
.