NAME

Data::LinkedList::Iterator::ListIterator - A list iterator to walk through a linked list.

SYNOPSIS

#!/usr/bin/env perl -w

use strict;
use Data::LinkedList;

my $list = Data::LinkedList->new();
$list->add_all(1, 2, 3, 4, 5);

my $iterator = $list->list_iterator(0);
CORE::say $iterator->next() while $iterator->has_next();

DESCRIPTION

The list iterator walks through a linked list in sequential order.

METHODS

new

Instantiates and returns a new Data::LinkedList::Iterator::ListIterator object. The starting index for the iterator has to be passed to the object upon construction.

my $list_iterator = Data::LinkedList::Iterator::ListIterator->new(
    list => Data::LinkedList->new() # Required for construction.
                                    # Won't complain if not passed, but will fail miserably.
);

next_index

Returns the position of the next entry.

$list_iterator->next_index();

previous_index

Returns the position of the previous entry.

$list_iterator->previous_index();

has_next

Returns a boolean value to represent if there is a next entry in the list.

$list_iterator->has_next();

has_previous

Returns a boolean value to represent if there is a previous entry in the list.

$list_iterator->has_previous();

next

Returns the next entry in the list.

$list_iterator->next();

previous

Returns the previous entry in the list.

$list_iterator->previous();

remove

Remove the most recently returned element from the list.

$list_iterator->remove();

add

Add an entry between the previous and next element and advance to the next element.

$list_iterator->add($element);

set

Change the entry data of the most recently returned entry.

$list_iterator->set($element);

BUGS

Please report any bugs to lloydg@cpan.org

AUTHOR

Lloyd Griffiths

COPYRIGHT

Copyright (c) 2013 Lloyd Griffiths

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.