System::Collections::Generic::LinkedList class

LinkedList class

LinkedList forward declaration.

template<typename T>class LinkedList : public virtual System::Object,
                                       public System::Collections::Generic::ICollection<T>,
                                       private System::Collections::Invalidatable
ParameterDescription
TContained value type.

Nested classes

Methods

MethodDescription
Add(const T&) overrideAdds element to the end of the list.
AddAfter(const SharedPtr<LinkedListNode<T>>&, const T&)Adds element after node of the list.
AddAfter(const SharedPtr<LinkedListNode<T>>&, const SharedPtr<LinkedListNode<T>>&)Adds newNode after node of the list.
AddBefore(const SharedPtr<LinkedListNode<T>>&, const T&)Adds element before node of the list.
AddBefore(const SharedPtr<LinkedListNode<T>>&, const SharedPtr<LinkedListNode<T>>&)Adds newNode before node of the list.
AddFirst(const T&)Adds element to the beginning of the list.
AddFirst(const SharedPtr<LinkedListNode<T>>&)Adds newNode to the beginning of the list.
AddLast(const T&)Adds element to the end of the list.
AddLast(const SharedPtr<LinkedListNode<T>>&)Adds newNode to the end of the list.
begin()Gets iterator to the first element of collection.
begin() constGets iterator to the first element of the const-qualified collection.
cbegin() constGets iterator to the first const-qualified element of collection.
cend() constGets iterator for a non-existent const-qualified element behind the end of the collection.
Clear() overrideDeletes all elements in list.
Contains(const T&) const overrideChecks if element is present in list.
CopyTo(ArrayPtr<T>, int) overrideCopies container data into existing array elements.
crbegin() constGets a reverse iterator to the last const-qualified element of collection (first in reverse).
crend() constGets a reverse iterator for a non-existent const-qualified element before the start of the collection.
end()Gets iterator for a non-existent element behind the end of the collection.
end() constGets iterator for a non-existent element behind the end of the const-qualified collection.
Find(const T&) constPerforms forward direction find of an element in the list.
FindLast(const T&) constPerforms reverse direction find of an element in the list.
get_Count() const overrideGets number of elements in list.
get_First() constGets pointer to the first element in the list.
get_Last() constGets pointer to the last element in the list.
GetEnumerator() overrideGets enumerator to iterate through current LinkedList.
LinkedList()Creates empty LinkedList.
LinkedList(const SharedPtr<IEnumerable<T>>&)Copy constructor.
rbegin()Gets a reverse iterator to the last element of collection (first in reverse).
rbegin() constGets a reverse iterator to the last element of the const-qualified collection (first in reverse).
Remove(const T&) overrideRemoves first occurance of the specified element from list.
Remove(const SharedPtr<LinkedListNode<T>>&)Removes node from list.
RemoveFirst()Removes first node from list.
RemoveLast()Removes last node from list.
rend()Gets a reverse iterator for a non-existent element before the start of the collection.
rend() constGets a reverse iterator for a non-existent element before the start of the const-qualified collection.
virtualizeBeginConstIterator() const overrideGets the implementation of begin const iterator for the current container.
virtualizeBeginIterator() overrideGets the implementation of begin iterator for the current container.
virtualizeEndConstIterator() const overrideGets the implementation of end const iterator for the current container.
virtualizeEndIterator() overrideGets the implementation of end iterator for the current container.

Typedefs

TypedefDescription
const_iteratorConst iterator type.
const_reverse_iteratorConst reverse iterator type.
iteratorIterator type.
list_tUnderlying data type.
reverse_iteratorReverse iterator type.

Remarks

Linked list container. Implements a wrapper over std::list. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

#include <system/collections/linkedlist.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

int main()
{
  // Create an instance of the LinkedList class.
  auto list = MakeObject<LinkedList<int>>();

  // Fill the linked list.
  list->AddFirst(1);
  list->AddLast(30);
  list->AddAfter(list->get_First(), 15);
  list->AddBefore(list->get_Last(), 25);

  // Print the linked list items.
  for (const auto item: list)
  {
    std::cout << item << ' ';
  }

  return 0;
}
/*
This code example produces the following output:
1 15 25 30
*/

See Also