DataStructure::LinkedList
A linked list data-structure, written in pure Perl.
See also DataStructure::DoubleList for a double-linked list version that offers a richer interface.
DataStructure::LinkedList->new(%options)
Creates an empty list.
The following options are available:
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).
shift
unshift
push
pop
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.
reverse
All the functions below are class methods that should be called on a DataStructure::LinkedList object. Unless documented otherwise, they run in constant time.
Returns the first DataStructure::LinkedList::Node of the list, or undef if the list is empty.
Returns the last DataStructure::LinkedList::Node of the list, or undef if the list is empty.
Adds a new node at the beginning of the list with the given value. Returns the newly added node.
Adds a new node at the end of the list with the given value. Returns the newly added node.
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().
pop()
shift()
Returns the number of nodes in the list.
Returns whether the list is empty.
Returns all the values of the list, as a normal Perl list. This runs in linear time with the size of the list.
DataStructure::DoubleList
Mathias Kende <mathias@cpan.org>
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:
Non-ASCII character seen before =encoding in 'node’s'. Assuming UTF-8
To install DataStructure, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DataStructure
CPAN shell
perl -MCPAN -e shell install DataStructure
For more information on module installation, please visit the detailed CPAN module installation guide.