LinkedList<T> 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이중으로 연결된 목록을 나타냅니다.
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class LinkedList : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class LinkedList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection
type LinkedList<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ICollection
type LinkedList<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ICollection
interface IDeserializationCallback
interface ISerializable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type LinkedList<'T> = class
interface ICollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
interface ISerializable
interface IDeserializationCallback
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type LinkedList<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface ICollection
interface IReadOnlyCollection<'T>
interface ISerializable
interface IDeserializationCallback
type LinkedList<'T> = class
interface ICollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T), IReadOnlyCollection(Of T)
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), ISerializable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), ISerializable
Public Class LinkedList(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T)
형식 매개 변수
- T
연결된 목록의 요소 형식을 지정합니다.
- 상속
-
LinkedList<T>
- 특성
- 구현
예제
다음 코드 예제에서는 LinkedList<T> 클래스의 많은 기능을 보여 줍니다.
#using <System.dll>
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
public ref class Example
{
public:
static void Main()
{
// Create the link list.
array<String^>^ words =
{ "the", "fox", "jumped", "over", "the", "dog" };
LinkedList<String^>^ sentence = gcnew LinkedList<String^>(words);
Display(sentence, "The linked list values:");
Console::WriteLine("sentence.Contains(\"jumped\") = {0}",
sentence->Contains("jumped"));
// Add the word 'today' to the beginning of the linked list.
sentence->AddFirst("today");
Display(sentence, "Test 1: Add 'today' to beginning of the list:");
// Move the first node to be the last node.
LinkedListNode<String^>^ mark1 = sentence->First;
sentence->RemoveFirst();
sentence->AddLast(mark1);
Display(sentence, "Test 2: Move first node to be last node:");
// Change the last node to 'yesterday'.
sentence->RemoveLast();
sentence->AddLast("yesterday");
Display(sentence, "Test 3: Change the last node to 'yesterday':");
// Move the last node to be the first node.
mark1 = sentence->Last;
sentence->RemoveLast();
sentence->AddFirst(mark1);
Display(sentence, "Test 4: Move last node to be first node:");
// Indicate the last occurence of 'the'.
sentence->RemoveFirst();
LinkedListNode<String^>^ current = sentence->FindLast("the");
IndicateNode(current, "Test 5: Indicate last occurence of 'the':");
// Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
sentence->AddAfter(current, "old");
sentence->AddAfter(current, "lazy");
IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':");
// Indicate 'fox' node.
current = sentence->Find("fox");
IndicateNode(current, "Test 7: Indicate the 'fox' node:");
// Add 'quick' and 'brown' before 'fox':
sentence->AddBefore(current, "quick");
sentence->AddBefore(current, "brown");
IndicateNode(current, "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.
mark1 = current;
LinkedListNode<String^>^ mark2 = current->Previous;
current = sentence->Find("dog");
IndicateNode(current, "Test 9: Indicate the 'dog' node:");
// The AddBefore method throws an InvalidOperationException
// if you try to add a node that already belongs to a list.
Console::WriteLine("Test 10: Throw exception by adding node (fox) already in the list:");
try
{
sentence->AddBefore(current, mark1);
}
catch (InvalidOperationException^ ex)
{
Console::WriteLine("Exception message: {0}", ex->Message);
}
Console::WriteLine();
// Remove the node referred to by mark1, and then add it
// before the node referred to by current.
// Indicate the node referred to by current.
sentence->Remove(mark1);
sentence->AddBefore(current, mark1);
IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):");
// Remove the node referred to by current.
sentence->Remove(current);
IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:");
// Add the node after the node referred to by mark2.
sentence->AddAfter(mark2, current);
IndicateNode(current, "Test 13: Add node removed in test 11 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->RemoveLast();
ICollection<String^>^ icoll = sentence;
icoll->Add("rhinoceros");
Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':");
Console::WriteLine("Test 16: Copy the list to an array:");
// Create an array with the same number of
// elements as the inked list.
array<String^>^ sArray = gcnew array<String^>(sentence->Count);
sentence->CopyTo(sArray, 0);
for each (String^ s in sArray)
{
Console::WriteLine(s);
}
// Release all the nodes.
sentence->Clear();
Console::WriteLine();
Console::WriteLine("Test 17: Clear linked list. Contains 'jumped' = {0}",
sentence->Contains("jumped"));
Console::ReadLine();
}
private:
static void Display(LinkedList<String^>^ words, String^ test)
{
Console::WriteLine(test);
for each (String^ word in words)
{
Console::Write(word + " ");
}
Console::WriteLine();
Console::WriteLine();
}
static void IndicateNode(LinkedListNode<String^>^ node, String^ test)
{
Console::WriteLine(test);
if (node->List == nullptr)
{
Console::WriteLine("Node '{0}' is not in the list.\n",
node->Value);
return;
}
StringBuilder^ result = gcnew StringBuilder("(" + node->Value + ")");
LinkedListNode<String^>^ nodeP = node->Previous;
while (nodeP != nullptr)
{
result->Insert(0, nodeP->Value + " ");
nodeP = nodeP->Previous;
}
node = node->Next;
while (node != nullptr)
{
result->Append(" " + node->Value);
node = node->Next;
}
Console::WriteLine(result);
Console::WriteLine();
}
};
int main()
{
Example::Main();
}
//This code example produces the following output:
//
//The linked list values:
//the fox jumped over the dog
//Test 1: Add 'today' to beginning of the list:
//today the fox jumped over the dog
//Test 2: Move first node to be last node:
//the fox jumped over the dog today
//Test 3: Change the last node to 'yesterday':
//the fox jumped over the dog yesterday
//Test 4: Move last node to be first node:
//yesterday the fox jumped over the dog
//Test 5: Indicate last occurence of 'the':
//the fox jumped over (the) dog
//Test 6: Add 'lazy' and 'old' after 'the':
//the fox jumped over (the) lazy old dog
//Test 7: Indicate the 'fox' node:
//the (fox) jumped over the lazy old dog
//Test 8: Add 'quick' and 'brown' before 'fox':
//the quick brown (fox) jumped over the lazy old dog
//Test 9: Indicate the 'dog' node:
//the quick brown fox jumped over the lazy old (dog)
//Test 10: Throw exception by adding node (fox) already in the list:
//Exception message: The LinkedList node belongs a LinkedList.
//Test 11: Move a referenced node (fox) before the current node (dog):
//the quick brown jumped 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 11 after a referenced node (brown):
//the quick brown (dog) jumped over the lazy old fox
//Test 14: Remove node that has the value 'old':
//the quick brown dog jumped over the lazy fox
//Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':
//the quick brown dog jumped over the lazy rhinoceros
//Test 16: Copy the list to an array:
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros
//Test 17: Clear linked list. Contains 'jumped' = False
//
using System;
using System.Text;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
// Create the link list.
string[] words =
{ "the", "fox", "jumps", "over", "the", "dog" };
LinkedList<string> sentence = new LinkedList<string>(words);
Display(sentence, "The linked list values:");
// Add the word 'today' to the beginning of the linked list.
sentence.AddFirst("today");
Display(sentence, "Test 1: Add 'today' to beginning of the list:");
// Move the first node to be the last node.
LinkedListNode<string> mark1 = sentence.First;
sentence.RemoveFirst();
sentence.AddLast(mark1);
Display(sentence, "Test 2: Move first node to be last node:");
// Change the last node to 'yesterday'.
sentence.RemoveLast();
sentence.AddLast("yesterday");
Display(sentence, "Test 3: Change the last node to 'yesterday':");
// Move the last node to be the first node.
mark1 = sentence.Last;
sentence.RemoveLast();
sentence.AddFirst(mark1);
Display(sentence, "Test 4: Move last node to be first node:");
// Indicate the last occurence of 'the'.
sentence.RemoveFirst();
LinkedListNode<string> current = sentence.FindLast("the");
IndicateNode(current, "Test 5: Indicate last occurence of 'the':");
// Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
sentence.AddAfter(current, "old");
sentence.AddAfter(current, "lazy");
IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':");
// Indicate 'fox' node.
current = sentence.Find("fox");
IndicateNode(current, "Test 7: Indicate the 'fox' node:");
// Add 'quick' and 'brown' before 'fox':
sentence.AddBefore(current, "quick");
sentence.AddBefore(current, "brown");
IndicateNode(current, "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.
mark1 = current;
LinkedListNode<string> mark2 = current.Previous;
current = sentence.Find("dog");
IndicateNode(current, "Test 9: Indicate the 'dog' node:");
// The AddBefore method throws an InvalidOperationException
// if you try to add a node that already belongs to a list.
Console.WriteLine("Test 10: Throw exception by adding node (fox) already in the list:");
try
{
sentence.AddBefore(current, mark1);
}
catch (InvalidOperationException ex)
{
Console.WriteLine("Exception message: {0}", ex.Message);
}
Console.WriteLine();
// Remove the node referred to by mark1, and then add it
// before the node referred to by current.
// Indicate the node referred to by current.
sentence.Remove(mark1);
sentence.AddBefore(current, mark1);
IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):");
// Remove the node referred to by current.
sentence.Remove(current);
IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:");
// Add the node after the node referred to by mark2.
sentence.AddAfter(mark2, current);
IndicateNode(current, "Test 13: Add node removed in test 11 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.RemoveLast();
ICollection<string> icoll = sentence;
icoll.Add("rhinoceros");
Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':");
Console.WriteLine("Test 16: Copy the list to an array:");
// Create an array with the same number of
// elements as the linked list.
string[] sArray = new string[sentence.Count];
sentence.CopyTo(sArray, 0);
foreach (string s in sArray)
{
Console.WriteLine(s);
}
Console.WriteLine("Test 17: linked list Contains 'jumps' = {0}",
sentence.Contains("jumps"));
// Release all the nodes.
sentence.Clear();
Console.WriteLine();
Console.WriteLine("Test 18: Cleared linked list Contains 'jumps' = {0}",
sentence.Contains("jumps"));
Console.ReadLine();
}
private static void Display(LinkedList<string> words, string test)
{
Console.WriteLine(test);
foreach (string word in words)
{
Console.Write(word + " ");
}
Console.WriteLine();
Console.WriteLine();
}
private static void IndicateNode(LinkedListNode<string> node, string test)
{
Console.WriteLine(test);
if (node.List == null)
{
Console.WriteLine("Node '{0}' is not in the list.\n",
node.Value);
return;
}
StringBuilder result = new StringBuilder("(" + node.Value + ")");
LinkedListNode<string> nodeP = node.Previous;
while (nodeP != null)
{
result.Insert(0, nodeP.Value + " ");
nodeP = nodeP.Previous;
}
node = node.Next;
while (node != null)
{
result.Append(" " + node.Value);
node = node.Next;
}
Console.WriteLine(result);
Console.WriteLine();
}
}
//This code example 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 LinkedList node belongs a LinkedList.
//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 11 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
//
Imports System.Text
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create the link list.
Dim words() As String = {"the", "fox", _
"jumps", "over", "the", "dog"}
Dim sentence As New LinkedList(Of String)(words)
Console.WriteLine("sentence.Contains(""jumps"") = {0}", _
sentence.Contains("jumps"))
Display(sentence, "The linked list values:")
' Add the word 'today' to the beginning of the linked list.
sentence.AddFirst("today")
Display(sentence, "Test 1: Add 'today' to beginning of the list:")
' Move the first node to be the last node.
Dim mark1 As LinkedListNode(Of String) = sentence.First
sentence.RemoveFirst()
sentence.AddLast(mark1)
Display(sentence, "Test 2: Move first node to be last node:")
' Change the last node to 'yesterday'.
sentence.RemoveLast()
sentence.AddLast("yesterday")
Display(sentence, "Test 3: Change the last node to 'yesterday':")
' Move the last node to be the first node.
mark1 = sentence.Last
sentence.RemoveLast()
sentence.AddFirst(mark1)
Display(sentence, "Test 4: Move last node to be first node:")
' Indicate the last occurence of 'the'.
sentence.RemoveFirst()
Dim current As LinkedListNode(Of String) = sentence.FindLast("the")
IndicateNode(current, "Test 5: Indicate last occurence of 'the':")
' Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).
sentence.AddAfter(current, "old")
sentence.AddAfter(current, "lazy")
IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':")
' Indicate 'fox' node.
current = sentence.Find("fox")
IndicateNode(current, "Test 7: Indicate the 'fox' node:")
' Add 'quick' and 'brown' before 'fox':
sentence.AddBefore(current, "quick")
sentence.AddBefore(current, "brown")
IndicateNode(current, "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.
mark1 = current
Dim mark2 As LinkedListNode(Of String) = current.Previous
current = sentence.Find("dog")
IndicateNode(current, "Test 9: Indicate the 'dog' node:")
' The AddBefore method throws an InvalidOperationException
' if you try to add a node that already belongs to a list.
Console.WriteLine("Test 10: Throw exception by adding node (fox) already in the list:")
Try
sentence.AddBefore(current, mark1)
Catch ex As InvalidOperationException
Console.WriteLine("Exception message: {0}", ex.Message)
End Try
Console.WriteLine()
' Remove the node referred to by mark1, and then add it
' before the node referred to by current.
' Indicate the node referred to by current.
sentence.Remove(mark1)
sentence.AddBefore(current, mark1)
IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):")
' Remove the node referred to by current.
sentence.Remove(current)
IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:")
' Add the node after the node referred to by mark2.
sentence.AddAfter(mark2, current)
IndicateNode(current, "Test 13: Add node removed in test 11 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.RemoveLast()
Dim icoll As ICollection(Of String) = sentence
icoll.Add("rhinoceros")
Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':")
Console.WriteLine("Test 16: Copy the list to an array:")
' Create an array with the same number of
' elements as the inked list.
Dim sArray() As String = New String((sentence.Count) - 1) {}
sentence.CopyTo(sArray, 0)
For Each s As String In sArray
Console.WriteLine(s)
Next
' Release all the nodes.
sentence.Clear()
Console.WriteLine()
Console.WriteLine("Test 17: Clear linked list. Contains 'jumps' = {0}", sentence.Contains("jumps"))
Console.ReadLine()
End Sub
Private Shared Sub Display(ByVal words As LinkedList(Of String), ByVal test As String)
Console.WriteLine(test)
For Each word As String In words
Console.Write((word + " "))
Next
Console.WriteLine()
Console.WriteLine()
End Sub
Private Shared Sub IndicateNode(ByVal node As LinkedListNode(Of String), ByVal test As String)
Console.WriteLine(test)
If IsNothing(node.List) Then
Console.WriteLine("Node '{0}' is not in the list." & vbLf, node.Value)
Return
End If
Dim result As StringBuilder = New StringBuilder(("(" _
+ (node.Value + ")")))
Dim nodeP As LinkedListNode(Of String) = node.Previous
While (Not (nodeP) Is Nothing)
result.Insert(0, (nodeP.Value + " "))
nodeP = nodeP.Previous
End While
node = node.Next
While (Not (node) Is Nothing)
result.Append((" " + node.Value))
node = node.Next
End While
Console.WriteLine(result)
Console.WriteLine()
End Sub
End Class
'This code example 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 LinkedList node belongs a LinkedList.
'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 11 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: Clear linked list. Contains 'jumps' = False
'
설명
LinkedList<T> 범용 연결된 목록입니다. .NET Framework의 다른 컬렉션 클래스와 일치하는 열거자를 지원하고 ICollection 인터페이스를 구현합니다.
LinkedList<T> LinkedListNode<T>형식의 별도 노드를 제공하므로 삽입 및 제거는 O(1) 작업입니다.
노드를 제거하고 동일한 목록이나 다른 목록에 다시 삽입할 수 있으므로 힙에 추가 개체가 할당되지 않습니다. 목록에 내부 개수도 유지되므로 Count 속성 가져오기는 O(1) 작업입니다.
LinkedList<T> 개체의 각 노드는 LinkedListNode<T>형식입니다. LinkedList<T> 이중으로 연결되므로 각 노드는 Next 노드를 앞으로 가리키고 Previous 노드를 뒤로 가리킵니다.
참조 형식이 포함된 목록은 노드와 해당 값을 동시에 만들 때 더 나은 성능을 발휘합니다.
LinkedList<T> 참조 형식에 대한 유효한 Value 속성으로 null
허용하고 중복 값을 허용합니다.
LinkedList<T> 비어 있으면 First 및 Last 속성에 null
포함됩니다.
LinkedList<T> 클래스는 목록을 일관성 없는 상태로 둘 수 있는 연결, 분할, 주기 또는 기타 기능을 지원하지 않습니다. 목록은 단일 스레드에서 일관성을 유지합니다. LinkedList<T> 지원하는 유일한 다중 스레드 시나리오는 다중 스레드 읽기 작업입니다.
생성자
LinkedList<T>() |
비어 있는 LinkedList<T> 클래스의 새 인스턴스를 초기화합니다. |
LinkedList<T>(IEnumerable<T>) |
지정된 IEnumerable 복사된 요소를 포함하고 복사된 요소 수를 수용할 수 있는 충분한 용량이 있는 LinkedList<T> 클래스의 새 인스턴스를 초기화합니다. |
LinkedList<T>(SerializationInfo, StreamingContext) |
사용되지 않음.
지정된 SerializationInfo 사용하여 직렬화할 수 있는 LinkedList<T> 클래스의 새 인스턴스를 초기화하고 StreamingContext. |
속성
Count |
LinkedList<T>실제로 포함된 노드 수를 가져옵니다. |
First |
LinkedList<T>첫 번째 노드를 가져옵니다. |
Last |
LinkedList<T>마지막 노드를 가져옵니다. |
메서드
명시적 인터페이스 구현
ICollection.CopyTo(Array, Int32) |
특정 Array 인덱스에서 시작하여 ICollection 요소를 Array복사합니다. |
ICollection.IsSynchronized |
ICollection 대한 액세스가 동기화되는지 여부를 나타내는 값을 가져옵니다(스레드로부터 안전). |
ICollection.SyncRoot |
ICollection대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다. |
ICollection<T>.Add(T) |
ICollection<T>끝에 항목을 추가합니다. |
ICollection<T>.IsReadOnly |
ICollection<T> 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
IEnumerable.GetEnumerator() |
연결된 목록을 컬렉션으로 반복하는 열거자를 반환합니다. |
IEnumerable<T>.GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
확장 메서드
적용 대상
스레드 보안
이 형식은 스레드로부터 안전하지 않습니다. 여러 스레드에서 LinkedList<T> 액세스해야 하는 경우 고유한 동기화 메커니즘을 구현해야 합니다.
컬렉션이 수정되지 않는 한 LinkedList<T> 여러 판독기를 동시에 지원할 수 있습니다. 그럼에도 불구하고 컬렉션을 열거하는 것은 본질적으로 스레드로부터 안전한 프로시저가 아닙니다. 드물게 열거형이 쓰기 액세스와 경합하는 경우 전체 열거형 중에 컬렉션을 잠가야 합니다. 읽기 및 쓰기를 위해 여러 스레드에서 컬렉션에 액세스할 수 있도록 하려면 고유한 동기화를 구현해야 합니다.
추가 정보
.NET