xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::linked_list< type_t, allocator_t > Class Template Reference
Inheritance diagram for xtd::collections::generic::linked_list< type_t, allocator_t >:
xtd::object

Definition

template<class type_t, class allocator_t>
class xtd::collections::generic::linked_list< type_t, allocator_t >

Represents a doubly linked list.

Definition
template<class type_t>
class linked_list : public xtd::object, public xtd::collections::generic::icollection <type_t>;
linked_list()=default
Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that is empty...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Header
#include <xtd/collections/generic/linked_list>
Namespace
xtd::collections::generic
Library
xtd.core
Examples
The following code example demonstrates many features of the xtd::collections::generic::linked_list <type_t> class.
#include <xtd/xtd>
using namespace text;
class example {
public:
static auto main() -> void {
// Create the link list.
auto sentence = linked_list<string> { "the", "fox", "jumps", "over", "the", "dog" };
display(sentence, "The linked list values:");
// Add the word 'today' to the beginning of the linked list.
sentence.add_first("today");
display(sentence, "Test 1: Add 'today' to beginning of the list:");
// Move the first node to be the last node.
auto node = *sentence.first();
sentence.remove(node);
sentence.add_last(node);
display(sentence, "Test 2: Move first node to be last node:");
// Change the last node to 'yesterday'.
sentence.remove_last();
sentence.add_last("yesterday");
display(sentence, "Test 3: Change the last node to 'yesterday':");
// Move the last node to be the first node.
node = *sentence.last();
sentence.remove(node);
sentence.add_first(node);
display(sentence, "Test 4: Move last node to be first node:");
// Indicate the last occurence of 'the'.
sentence.remove_first();
node = *sentence.find_last("the");
indicate_node(node, "Test 5: Indicate last occurence of 'the':");
// Add 'lazy' and 'old' after 'the' (the linked_list_node named node).
sentence.add_after(node, "old");
sentence.add_after(*sentence.find_last("the"), "lazy");
indicate_node(*sentence.find_last("the"), "Test 6: Add 'lazy' and 'old' after 'the':");
// Indicate 'fox' node.
node = *sentence.find_last("fox");
indicate_node(node, "Test 7: Indicate the 'fox' node:");
// Add 'quick' and 'brown' before 'fox':
sentence.add_before(*sentence.find("fox"), "quick");
sentence.add_before(*sentence.find("fox"), "brown");
indicate_node(*sentence.find("fox"), "Test 8: Add 'quick' and 'brown' before 'fox':");
// Keep a reference to the current node, 'fox', and to the previous node in the list. Indicate the 'dog' node.
node = *sentence.find_last("dog")->previous();
indicate_node(*sentence.find("dog"), "Test 9: Indicate the 'dog' node:");
// The add_before method throws an invalid_operation_exception if you try to add a node that already belongs to a list.
console::write_line("Test 10: Throw exception by adding node (fox) already in the list:");
try {
sentence.add_before(*sentence.find("fox"), node);
} catch (const invalid_operation_exception& ex) {
console::write_line("Exception message: {}", ex.message());
}
// Remove the 'fox' node, and then add it before the 'dog' node.
// Indicate the node referred to by current.
node = *sentence.find("fox");
sentence.remove(node);
sentence.add_before(*sentence.find("dog"), node);
node = *sentence.find("dog");
indicate_node(node, "Test 11: Move a referenced node (fox) before the current node (dog):");
// Remove the node referred to by node.
sentence.remove(node);
node = sentence.find("dog") ? *sentence.find("dog") : linked_list_node<string>("dog");
indicate_node(node, "Test 12: Remove current node (dog) and attempt to indicate it:");
// Add the node after the 'brown' node.
sentence.add_after(*sentence.find("brown"), node);
indicate_node(node, "Test 13: Add node removed in test 12 after a referenced node (brown):");
// The Remove method finds and removes the first node that that has the specified value.
sentence.remove("old");
display(sentence, "Test 14: Remove node that has the value 'old':");
// When the linked list is cast to icollection(Of string), the add method adds a node to the end of the list.
sentence.remove_last();
auto& icoll = as<icollection<string>>(sentence);
icoll.add("rhinoceros");
display(sentence, "Test 15: Remove last node, cast to icollection, and add 'rhinoceros':");
console::write_line("Test 16: Copy the list to an array:");
// Create an array with the same number of elements as the linked list.
auto sarray = array<string>(sentence.count());
sentence.copy_to(sarray, 0);
for (auto s : sarray)
console::write_line("Test 17: linked list Contains 'jumps' = {0}", sentence.contains("jumps"));
// Release all the nodes.
sentence.clear();
console::write_line("Test 18: Cleared linked list Contains 'jumps' = {0}", sentence.contains("jumps"));
}
static void display(const linked_list<string>& words, const string& test) {
for (auto word : words)
console::write(word + " ");
}
static void indicate_node(const linked_list_node<string>& node, const string& test) {
auto l = node.list();
if (!l) {
console::write_line("Node '{0}' is not in the list.\n", node.value());
return;
}
auto result = string_builder {"(" + node.value() + ")"};
auto node_previous = node.previous();
while (node_previous) {
result.insert(0, node_previous->value() + " ");
node_previous = node_previous->previous();
}
auto node_next = node.next();
while (node_next) {
result.append(" " + node_next->value());
node_next = node_next->next();
}
}
};
startup_(example::main);
// This code produces the following output :
//
// The linked list values:
// the fox jumps over the dog
//
// Test 1: Add 'today' to beginning of the list:
// today the fox jumps over the dog
//
// Test 2: Move first node to be last node:
// the fox jumps over the dog today
//
// Test 3: Change the last node to 'yesterday':
// the fox jumps over the dog yesterday
//
// Test 4: Move last node to be first node:
// yesterday the fox jumps over the dog
//
// Test 5: Indicate last occurence of 'the':
// the fox jumps over (the) dog
//
// Test 6: Add 'lazy' and 'old' after 'the':
// the fox jumps over (the) lazy old dog
//
// Test 7: Indicate the 'fox' node:
// the (fox) jumps over the lazy old dog
//
// Test 8: Add 'quick' and 'brown' before 'fox':
// the quick brown (fox) jumps over the lazy old dog
//
// Test 9: Indicate the 'dog' node:
// the quick brown fox jumps over the lazy old (dog)
//
// Test 10: Throw exception by adding node (fox) already in the list:
// Exception message: The linked_list node belongs a linked_list.
//
// Test 11: Move a referenced node (fox) before the current node (dog):
// the quick brown jumps over the lazy old fox (dog)
//
// Test 12: Remove current node (dog) and attempt to indicate it:
// Node 'dog' is not in the list.
//
// Test 13: Add node removed in test 12 after a referenced node (brown):
// the quick brown (dog) jumps over the lazy old fox
//
// Test 14: Remove node that has the value 'old':
// the quick brown dog jumps over the lazy fox
//
// Test 15: Remove last node, cast to icollection, and add 'rhinoceros':
// the quick brown dog jumps over the lazy rhinoceros
//
// Test 16: Copy the list to an array:
// the
// quick
// brown
// dog
// jumps
// over
// the
// lazy
// rhinoceros
//
// Test 17: linked list Contains 'jumps' = true
//
// Test 18: Cleared linked list Contains 'jumps' = false
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
virtual const xtd::string & message() const noexcept
Gets message associate to the exception.
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition invalid_operation_exception.hpp:18
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
xtd::text::basic_string_builder< char > string_builder
Represents a mutable string of characters of UTF-8 code units. This class cannot be inherited.
Definition string_builder.hpp:19
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ s
The S key.
Definition console_key.hpp:124
@ l
The L key.
Definition console_key.hpp:110
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:17
Remarks
xtd::collections::generic::linked_list <type_t> is a general-purpose linked list. It supports enumerators and implements the xtd::collections::generic::icollection interface, consistent with other collection classes in the xtd Framework.
xtd::collections::generic::linked_list <type_t> provides separate nodes of type xtd::collections::generic::linked_list_node <type_t>, so insertion and removal are O(1) operations.
You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional objects allocated on the heap. Because the list also maintains an internal count, getting the xtd::collections::generic::linked_list::count property is an O(1) operation.
Each node in a xtd::collections::generic::linked_list <type_t> object is of the type xtd::collections::generic::linked_list_node <type_t>. Because the xtd::collections::generic::linked_list <type_t> is doubly linked, each node points forward to the xtd::collections::generic::linked_list_node::next node and backward to the xtd::collections::generic::linked_list_node::previous node.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain xtd::nullopt.
The xtd::collections::generic::linked_list <typ_t> class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state. The list remains consistent on a single thread. The only multithreaded scenario supported by xtd::collections::generic::linked_list <type_t> is multithreaded read operations.
Linq extension
  • As xtd::collections::generic::linked_list <type_t> inherits the xtd::collections::generic::ienumerable <type_t> interface, it automatically inherits the xtd::collections::generic::extensions::enumerable <type_t> interface and at the same time all the methods of xtd::linq::enumerable.
  • Thanks to xtd::linq, xtd::collections::generic::linked_list <type_t> can be manipulated by the classes of xtd::ranges::views and can be combined with std::ranges.
    The following example shows the xtd::ranges::views and std::ranges usage :
    #include <xtd/xtd>
    auto main() -> int {
    //string names[] = {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David"};
    //auto names = fixed_array<string, 8> {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David"};
    //auto names = std::vector {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    //auto names = std::list {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    //auto names = array {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    //auto names = list {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    //auto names = linked_list {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    auto names = {"Burke"_s, "Connor"_s, "Frank"_s, "Everett"_s, "Albert"_s, "George"_s, "Harris"_s, "David"_s};
    // xtd::linq query
    auto query1 = from(names)
    .where(delegate_(auto s) {return s.length() == 5;})
    .order_by(delegate_(auto s) {return s;})
    .select(delegate_(auto s) {return s.to_upper();});
    println(query1);
    // xtd::ranges query
    auto query2 = names
    | where(delegate_(auto s) {return s.length() == 5;})
    | order_by(delegate_(auto s) {return s;})
    | select(delegate_(auto s) {return s.to_upper();});
    println(query2);
    // std::ranges combined with xtd::ranges query
    auto query3 = names
    | std::views::filter(delegate_(auto s) {return s.length() == 5;})
    | order_by(delegate_(auto s) {return s;})
    | std::views::transform(delegate_(auto s) {return s.to_upper();});
    println(query3);
    }
    // Console output :
    //
    // [BURKE, DAVID, FRANK]
    // [BURKE, DAVID, FRANK]
    // [BURKE, DAVID, FRANK]
    #define delegate_
    The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
    Definition delegate.hpp:924
    constexpr auto select
    The xtd::ranges::views::select instance.
    Definition select.hpp:40
    constexpr auto order_by
    The xtd::ranges::views::order_by instance.
    Definition order_by.hpp:40
    @ select
    The SELECT key.
    Definition console_key.hpp:54
    void println(FILE *file)
    Writes the current line terminator to the file output stream using the specified format information.
    Definition println.hpp:14
Performance considerations
As xtd::collections::generic::linked_list <type_t> instantiates and uses only the methods of std::list, the performance of xtd::collections::generic::linked_list <type_t> is practically identical to that of std::list.

Public Aliases

using value_type
 Represents the list value type.
 
using base_type
 Represents the list base type.
 
using size_type
 Represents the list size type (usually xtd::size).
 
using reference
 Represents the reference of list value type.
 
using const_reference
 Represents the const reference of list value type.
 

Public Constructors

 linked_list ()=default
 Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that is empty.
 
 linked_list (linked_list &&list)=default
 Move constructor with specified list.
 
 linked_list (const linked_list &list)
 Default copy constructor with specified list.
 
 linked_list (base_type &&list)
 Move constructor with specified base type list.
 
 linked_list (const base_type &list)
 Copy constructor with specified base type list.
 
 linked_list (const xtd::collections::generic::ienumerable< type_t > &collection)
 Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable and has sufficient capacity to accommodate the number of elements copied.
 
 linked_list (std::initializer_list< type_t > items)
 Constructs the container with the contents of the specified initializer list, and allocator.
 
template<std::input_iterator input_iterator_t>
 linked_list (input_iterator_t first, input_iterator_t last)
 Constructs the container with the contents of the range [first, last).
 

Public Properties

auto count () const noexcept -> size_type override
 Gets the number of nodes actually contained in the xtd::collections::generic::linked_list <type_t>.
 
auto first () const noexcept -> xtd::optional< linked_list_node< type_t > >
 Gets the first node of the xtd::collections::generic::linked_list <type_t>.
 
auto first () noexcept -> xtd::optional< linked_list_node< type_t > >
 Gets the first node of the xtd::collections::generic::linked_list <type_t>.
 
auto items () const noexcept -> const base_type &
 Returns the underlying base type items.
 
auto items () noexcept -> base_type &
 Returns the underlying base type items.
 
auto last () const noexcept -> xtd::optional< linked_list_node< type_t > >
 Gets the last node of the xtd::collections::generic::linked_list <type_t>.
 
auto last () noexcept -> xtd::optional< linked_list_node< type_t > >
 Gets the last node of the xtd::collections::generic::linked_list <type_t>.
 

Public Methods

auto add_after (const linked_list_node< type_t > &node, const type_t &value) -> linked_list_node< type_t >
 Adds a new node containing the specified value after the specified existing node in the xtd::collections::generic::linked_list <type_t>.
 
auto add_after (const linked_list_node< type_t > &node, linked_list_node< type_t > &new_node) -> void
 Adds the specified new node after the specified existing node in the xtd::collections::generic::linked_list <type_t>.
 
auto add_before (const linked_list_node< type_t > &node, const type_t &value) -> linked_list_node< type_t >
 Adds a new node containing the specified value before the specified existing node in the xtd::collections::generic::linked_list <type_t>.
 
auto add_before (const linked_list_node< type_t > &node, linked_list_node< type_t > &new_node) -> void
 Adds the specified new node before the specified existing node in the xtd::collections::generic::linked_list <type_t>.
 
auto add_first (const type_t &value) -> linked_list_node< type_t >
 Adds a new node containing the specified value at the start of the xtd::collections::generic::linked_list <type_t>.
 
auto add_first (linked_list_node< type_t > &node) -> void
 Adds the specified new node at the start of the xtd::collections::generic::linked_list <type_t>.
 
auto add_last (const type_t &value) -> linked_list_node< type_t >
 Adds a new node containing the specified value at the end of the xtd::collections::generic::linked_list <type_t>.
 
auto add_last (linked_list_node< type_t > &node) -> void
 Adds the specified new node at the end of the xtd::collections::generic::linked_list <type_t>.
 
auto clear () -> void override
 Removes all elements from the xtd::collections::generic::linked_list <type_t>.
 
auto contains (const type_t &value) const noexcept -> bool override
 Determines whether an element is in the xtd::colllections::generic::linked_list <type_t>.
 
auto copy_to (xtd::array< type_t > &array, size_type array_index) const -> void override
 Copies the entire xtd::colllections::generic::linked_list <type_t> to a compatible one-dimensional array, starting at the specified index of the target array.
 
auto find (const type_t value) const noexcept -> xtd::optional< linked_list_node< type_t > >
 Finds the first node that contains the specified value.
 
auto find_last (const type_t value) const noexcept -> xtd::optional< linked_list_node< type_t > >
 Finds the last node that contains the specified value.
 
enumerator< value_typeget_enumerator () const noexcept override
 Returns an enumerator that iterates through the xtd::collections::generic::linked_list <type_t>.
 
auto remove (const type_t &item) noexcept -> bool override
 Removes the first occurrence of a specific object from the xtd::collections::generic::linked_list <type_t>.
 
auto remove (linked_list_node< type_t > &node) -> void
 Removes the specified node from the xtd::collections::generic::linked_list <type_t>.
 
auto remove_first () -> void
 Removes the node at the start of the xtd::collections::generic::linked_list <type_t>.
 
auto remove_last () -> void
 Removes the node at the end of the xtd::collections::generic::linked_list <type_t>.
 
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
 

Public Operators

auto operator= (const linked_list &other) -> linked_list &=default
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
 
auto operator= (linked_list &&other) noexcept -> linked_list &
 Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.
 
auto operator= (const std::initializer_list< type_t > &items) -> linked_list &
 Replaces the contents with those identified by initializer list ilist.
 
 operator const base_type & () const noexcept
 Returns a reference to the underlying base type.
 
 operator base_type & () noexcept
 Returns a reference to the underlying base type.
 

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Member Typedef Documentation

◆ value_type

template<class type_t, class allocator_t>
using xtd::collections::generic::linked_list< type_t, allocator_t >::value_type

Represents the list value type.

◆ base_type

template<class type_t, class allocator_t>
using xtd::collections::generic::linked_list< type_t, allocator_t >::base_type

Represents the list base type.

◆ size_type

template<class type_t, class allocator_t>
using xtd::collections::generic::linked_list< type_t, allocator_t >::size_type

Represents the list size type (usually xtd::size).

◆ reference

template<class type_t, class allocator_t>
using xtd::collections::generic::linked_list< type_t, allocator_t >::reference

Represents the reference of list value type.

◆ const_reference

template<class type_t, class allocator_t>
using xtd::collections::generic::linked_list< type_t, allocator_t >::const_reference

Represents the const reference of list value type.

Constructor & Destructor Documentation

◆ linked_list() [1/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( )
default

Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that is empty.

Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain std::nullopt.
This constructor is an O(1) operation.

◆ linked_list() [2/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( linked_list< type_t, allocator_t > && list)
default

Move constructor with specified list.

Parameters
listThe xtd::collections::generic::linked_list <type_t> which elements will be moved from.

◆ linked_list() [3/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( const linked_list< type_t, allocator_t > & list)
inline

Default copy constructor with specified list.

Parameters
linked_listThe xtd::collections::generic::linked_list <type_t> which elements will be inserted from.

◆ linked_list() [4/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( base_type && list)
inline

Move constructor with specified base type list.

Parameters
listThe xtd::collections::generic::linked_list::base_type which elements will be moved from.

◆ linked_list() [5/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( const base_type & list)
inline

Copy constructor with specified base type list.

Parameters
listThe xtd::collections::generic::linked_list::base_type which elements will be inserted from.

◆ linked_list() [6/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( const xtd::collections::generic::ienumerable< type_t > & collection)
inline

Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable and has sufficient capacity to accommodate the number of elements copied.

Parameters
collectionThe xtd::collections::generic::ienumerable whose elements are copied to the new xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If collection has no elements then the new xtd::collections::generic::linked_list <type_t> is empty, and the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain xtd::nullopt.
This constructor is an O(n) operation, where n is the number of elements in collection.

◆ linked_list() [7/8]

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( std::initializer_list< type_t > items)
inline

Constructs the container with the contents of the specified initializer list, and allocator.

Parameters
itemsThe initializer list to initialize the elements of the container with.

◆ linked_list() [8/8]

template<class type_t, class allocator_t>
template<std::input_iterator input_iterator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::linked_list ( input_iterator_t first,
input_iterator_t last )
inline

Constructs the container with the contents of the range [first, last).

Parameters
firstThe first iterator the range to copy the elements from.
lastThe last iterator the range to copy the elements from.

Member Function Documentation

◆ count()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::count ( ) const -> size_type
inlineoverridenoexcept

Gets the number of nodes actually contained in the xtd::collections::generic::linked_list <type_t>.

Returns
The number of nodes actually contained in the xtd::collections::generic::linked_list <type_t>.
Remarks
Retrieving the value of this property is an O(1) operation.

◆ first() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::first ( ) const -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Gets the first node of the xtd::collections::generic::linked_list <type_t>.

Returns
The first xtd::collections::generic::linked_list_node <type_t> of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain std::nullopt.
Retrieving the value of this property is an O(1) operation.

◆ first() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::first ( ) -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Gets the first node of the xtd::collections::generic::linked_list <type_t>.

Returns
The first xtd::collections::generic::linked_list_node <type_t> of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain std::nullopt.
Retrieving the value of this property is an O(1) operation.

◆ items() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::items ( ) const -> const base_type&
inlinenoexcept

Returns the underlying base type items.

Returns
The underlying base type items.
Remarks
Retrieving the value of this property is an O(1) operation.

◆ items() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::items ( ) -> base_type&
inlinenoexcept

Returns the underlying base type items.

Returns
The underlying base type items.
Remarks
Retrieving the value of this property is an O(1) operation.

◆ last() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::last ( ) const -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Gets the last node of the xtd::collections::generic::linked_list <type_t>.

Returns
The last xtd::collections::generic::linked_list_node <type_t> of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain std::nullopt.
Retrieving the value of this property is an O(1) operation.

◆ last() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::last ( ) -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Gets the last node of the xtd::collections::generic::linked_list <type_t>.

Returns
The last xtd::collections::generic::linked_list_node <type_t> of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
If the xtd::collections::generic::linked_list <type_t> is empty, the xtd::collections::generic::linked_list::first and xtd::collections::generic::linked_list::last properties contain std::nullopt.
Retrieving the value of this property is an O(1) operation.

◆ add_after() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_after ( const linked_list_node< type_t > & node,
const type_t & value ) -> linked_list_node<type_t>
inline

Adds a new node containing the specified value after the specified existing node in the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe xtd::collections::generic::linked_list_node <type_t> after which to insert value.
valueThe value to add to the xtd::collections::generic::linked_list <type_t>.
Returns
The new xtd::collections::generic::linked_list_node <type_t> containing value.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_after() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_after ( const linked_list_node< type_t > & node,
linked_list_node< type_t > & new_node ) -> void
inline

Adds the specified new node after the specified existing node in the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe xtd::collections::generic::linked_list_node <type_t> after which to insert new_node.
new_nodeThe new xtd::collections::generic::linked_list_node <type_t> to add to the xtd::collections::generic::linked_list <type_t>.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
-or-
`new_node` belongs to another xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_before() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_before ( const linked_list_node< type_t > & node,
const type_t & value ) -> linked_list_node<type_t>
inline

Adds a new node containing the specified value before the specified existing node in the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe xtd::collections::generic::linked_list_node <type_t> before which to insert value.
valueThe value to add to the xtd::collections::generic::linked_list <type_t>.
Returns
The new xtd::collections::generic::linked_list_node <type_t> containing value.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_before() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_before ( const linked_list_node< type_t > & node,
linked_list_node< type_t > & new_node ) -> void
inline

Adds the specified new node before the specified existing node in the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe xtd::collections::generic::linked_list_node <type_t> before which to insert new_node.
new_nodeThe new xtd::collections::generic::linked_list_node <type_t> to add to the xtd::collections::generic::linked_list <type_t>.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
-or-
`new_node` belongs to another xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_first() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_first ( const type_t & value) -> linked_list_node<type_t>
inline

Adds a new node containing the specified value at the start of the xtd::collections::generic::linked_list <type_t>.

Parameters
valueThe value to add at the start of the start of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_first() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_first ( linked_list_node< type_t > & node) -> void
inline

Adds the specified new node at the start of the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe new xtd::collections::generic::linked_list_node <type_t> to add at the start of the xtd::collections::generic::linked_list <type_t>.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_last() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_last ( const type_t & value) -> linked_list_node<type_t>
inline

Adds a new node containing the specified value at the end of the xtd::collections::generic::linked_list <type_t>.

Parameters
valueThe value to add at the start of the end of the xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ add_last() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::add_last ( linked_list_node< type_t > & node) -> void
inline

Adds the specified new node at the end of the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe new xtd::collections::generic::linked_list_node <type_t> to add at the end of the xtd::collections::generic::linked_list <type_t>.
Exceptions
xtd::invalid_operation_exception`node` is not in the current xtd::collections::generic::linked_list <type_t>.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
Retrieving the value of this property is an O(1) operation.

◆ clear()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::clear ( ) -> void
inlineoverride

Removes all elements from the xtd::collections::generic::linked_list <type_t>.

Remarks
xtd::collections::generic::linked_list::count is set to 0, and references to other objects from elements of the collection are also released.
xtd::collections::generic::linked_list::capacity remains unchanged. To reset the capacity of the xtd::collections::generic::linked_list <type_t>, call the xtd::collections::generic::linked_list::trim_excess method or set the xtd::collections::generic::linked_list::capacity property directly. Decreasing the capacity reallocates memory and copies all the elements in the xtd::collections::generic::linked_list <type_t>. Trimming an empty xtd::collections::generic::linked_list <type_t> sets the capacity of the xtd::collections::generic::linked_list <type_t> to the default capacity.
This method is an O(n) operation, where n is xtd::collections::generic::linked_list::count.

◆ contains()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::contains ( const type_t & value) const -> bool
inlineoverridenoexcept

Determines whether an element is in the xtd::colllections::generic::linked_list <type_t>.

Parameters
valueThe object to locate in the xtd::colllections::generic::linked_list <type_t>. The value can be null for reference types.
Returns
true if item is found in the xtd::colllections::generic::linked_list <type_t>; otherwise, false.

◆ copy_to()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::copy_to ( xtd::array< type_t > & array,
size_type array_index ) const -> void
inlineoverride

Copies the entire xtd::colllections::generic::linked_list <type_t> to a compatible one-dimensional array, starting at the specified index of the target array.

Parameters
arrayThe one-dimensional Array that is the destination of the elements copied from xtd::colllections::generic::linked_list <type_t>. The Array must have zero-based indexing.
array_indexThe zero-based index in array at which copying begins.
Exceptions
xtd::argument_out_of_range_exceptionThe number of elements in the source xtd::colllections::generic::linked_list <type_t> is greater than the available space from arrayIndex to the end of the destination array.
Remarks
This method uses xtd::array::copy to copy the elements.
The elements are copied to the xtd::array in the same order in which the enumerator iterates through the xtd::colllections::generic::linked_list <type_t>.
This method is an O(n) operation, where n is xtd::colllections::generic::linked_list::count.

◆ find()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::find ( const type_t value) const -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Finds the first node that contains the specified value.

Parameters
valueThe value to locate in the xtd::collections::generic::linked_list <type_t>.
Returns
The first xtd::collections::generic::linked_list_node <type_t> that contains the specified value, if found; otherwise, xtd::nullopt.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
This method performs a linear search; therefore, this method is an O(n) operation, where n is xtd::collections::generic::linked_list::count.

◆ find_last()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::find_last ( const type_t value) const -> xtd::optional<linked_list_node<type_t>>
inlinenoexcept

Finds the last node that contains the specified value.

Parameters
valueThe value to locate in the xtd::collections::generic::linked_list <type_t>.
Returns
The last xtd::collections::generic::linked_list_node <type_t> that contains the specified value, if found; otherwise, xtd::nullopt.
Remarks
xtd::collections::generic::linked_list <type_t> allows duplicate values.
This method performs a linear search; therefore, this method is an O(n) operation, where n is xtd::collections::generic::linked_list::count.

◆ get_enumerator()

template<class type_t, class allocator_t>
enumerator< value_type > xtd::collections::generic::linked_list< type_t, allocator_t >::get_enumerator ( ) const
inlineoverridenoexcept

Returns an enumerator that iterates through the xtd::collections::generic::linked_list <type_t>.

Returns
A xtd::collections::generic::.enumerator for the xtd::collections::generic::linked_list <type_t>.

◆ remove() [1/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::remove ( const type_t & item) -> bool
inlineoverridenoexcept

Removes the first occurrence of a specific object from the xtd::collections::generic::linked_list <type_t>.

Parameters
itemThe object to remove from the xtd::collections::generic::linked_list <type_t>.
Returns
true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the xtd::collections::generic::linked_list <type_t>.
Remarks
If type typ_t implements the xtd::iequatable <type_t> generic interface, the equality comparer is the xtd::iequatable::equals method of that interface; otherwise, the default equality comparer is xtd::object::equals.
This method performs a linear search; therefore, this method is an O(n) operation, where n is xtd::collections::generic::linked_list::count.

◆ remove() [2/2]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::remove ( linked_list_node< type_t > & node) -> void
inline

Removes the specified node from the xtd::collections::generic::linked_list <type_t>.

Parameters
nodeThe xtd::collections::generic::linked_list_node <type_t> to remove from the xtd::collections::generic::linked_list <type_t>.
Exceptions
xtd::invalid_operation_exceptionnode is not in the current xtd::collections::generic::linked_list <type_t>.
Remarks
This method is an O(1) operation.

◆ remove_first()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::remove_first ( ) -> void
inline

Removes the node at the start of the xtd::collections::generic::linked_list <type_t>.

Exceptions
xtd::invalid_operation_exceptionThe xtd::collections::generic::linked_list <type_t> is empty.
Remarks
This method is an O(1) operation.

◆ remove_last()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::remove_last ( ) -> void
inline

Removes the node at the end of the xtd::collections::generic::linked_list <type_t>.

Exceptions
xtd::invalid_operation_exceptionThe xtd::collections::generic::linked_list <type_t> is empty.
Remarks
This method is an O(1) operation.

◆ to_string()

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::to_string ( ) const -> xtd::string
inlineoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ operator=() [1/3]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::operator= ( const linked_list< type_t, allocator_t > & other) -> linked_list &=default
default

Copy assignment operator. Replaces the contents with a copy of the contents of other.

Parameters
otherAnother container to use as data source.
Returns
This current instance.

◆ operator=() [2/3]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::operator= ( linked_list< type_t, allocator_t > && other) -> linked_list&
inlinenoexcept

Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.

Parameters
otherAnother base type container to use as data source.
Returns
This current instance.

◆ operator=() [3/3]

template<class type_t, class allocator_t>
auto xtd::collections::generic::linked_list< type_t, allocator_t >::operator= ( const std::initializer_list< type_t > & items) -> linked_list&
inline

Replaces the contents with those identified by initializer list ilist.

Parameters
itemsInitializer list to use as data source
Returns
This current instance.

◆ operator const base_type &()

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::operator const base_type & ( ) const
inlinenoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

◆ operator base_type &()

template<class type_t, class allocator_t>
xtd::collections::generic::linked_list< type_t, allocator_t >::operator base_type & ( )
inlinenoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

The documentation for this class was generated from the following file: