NAME

DataStructure::LinkedList

SYNOPSIS

A linked list data-structure, written in pure Perl.

See also DataStructure::DoubleList for a double-linked list version that offers a richer interface.

DESCRIPTION

CONSTRUCTOR

DataStructure::LinkedList->new(%options)

Creates an empty list.

The following options are available:

reverse

By default this class implements the standard shift and unshift methods that operate on the beginning of the list and the push method that operates on the end of the list. And pop is a synonym for shift (so not the opposite of push).

If the reverse option is set to a true value then the semantics of the list is reversed and pop and push operate on the beginning of the list, unshift operates on the end of the list and shift becomes a synonym for pop.

METHODS

All the functions below are class methods that should be called on a DataStructure::LinkedList object. Unless documented otherwise, they run in constant time.

first()

Returns the first DataStructure::LinkedList::Node of the list, or undef if the list is empty.

last()

Returns the last DataStructure::LinkedList::Node of the list, or undef if the list is empty.

unshift($value)

Adds a new node at the beginning of the list with the given value. Returns the newly added node.

push($value)

Adds a new node at the end of the list with the given value. Returns the newly added node.

shift()

Removes the first node of the list and returns its value. Returns undef if the list is empty. Note that the method can also return undef if the first node’s value is undef

For convenience, pop() can be used as a synonym of shift().

size()

Returns the number of nodes in the list.

empty()

Returns whether the list is empty.

values()

Returns all the values of the list, as a normal Perl list. This runs in linear time with the size of the list.

SEE ALSO

DataStructure::DoubleList

AUTHOR

Mathias Kende <mathias@cpan.org>

LICENCE

Copyright 2021 Mathias Kende

This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 173:

Non-ASCII character seen before =encoding in 'node’s'. Assuming UTF-8