LinkedListとは? わかりやすく解説

Weblio 辞書 > コンピュータ > IT用語辞典 > LinkedListの意味・解説 

連結リスト

読み方:れんけつリスト
【英】linked list

連結リストとは、データ構造の一種であるリストの中で、自分の次、および、前の要素を示す情報(リンク情報)を持つことで、要素を連結(リンク)させたリストのことである。

リストは、データの要素を順番に並べて扱うデータ構造のことである。

次の要素へのリンクしか持たない連結リストのことを単方向(一方向)リスト、次と前への要素へのリンクを持つものを双方向リストと言うこともある。

連結リストは配列とは違い、リンクを辿らないと各々の要素にアクセスができず、また、リンクのためのメモリを余分に持つ必要があるなど不利な点がある。しかし、データの個数が前もってわからないような場合や、データの追加や削除が頻繁に発生するような場合などの扱いには適している。


LinkedList コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

LinkedList クラスの新しい空のインスタンスを初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Dim instance As New LinkedList(Of
 T)
public LinkedList ()
public:
LinkedList ()
public LinkedList ()
解説解説

LinkedList は、null 参照 (Visual Basic では Nothing) を参照型に対して有効な Value として受け取り、値の重複を許可します。

LinkedList が空の場合、First プロパティと Last プロパティには null 参照 (Visual Basic では Nothing) が格納されます。

このコンストラクタは O(1) 操作です。

使用例使用例

String 型の LinkedList を作成および初期化し、いくつかのノードを追加し、その内容を表示するコード例を次に示します。

Imports System
Imports System.Collections
Imports System.Collections.Generic

Public Class GenericCollection

    Public Shared Sub Main()

        ' Create and initialize a new LinkedList.
        Dim ll As New LinkedList(Of
 String)()
        ll.AddLast("red")
        ll.AddLast("orange")
        ll.AddLast("yellow")
        ll.AddLast("orange")

        ' Display the contents of the LinkedList.
        If ll.Count > 0 Then
            Console.WriteLine("The first item in the list is {0}.",
 ll.First.Value)
            Console.WriteLine("The last item in the list is {0}.",
 ll.Last.Value)

            Console.WriteLine("The LinkedList contains:")
            For Each s As
 String In  ll
                Console.WriteLine("   {0}", s)
            Next s 
        Else
            Console.WriteLine("The LinkedList is empty.")
        End If

    End Sub 

End Class 

'This code produces the following output.
'
'The first item in the list is <null>.
'The last item in the list is orange.
'The LinkedList contains:
'   red
'   orange
'   yellow
'   orange

using System;
using System.Collections;
using System.Collections.Generic;

public class GenericCollection  
{
   public static void Main()
  
   {
      // Create and initialize a new LinkedList.
      LinkedList<String> ll = new LinkedList<String>();
      ll.AddLast( "red" );
      ll.AddLast( "orange" );
      ll.AddLast( "yellow" );
      ll.AddLast( "orange" );

      // Display the contents of the LinkedList.
      if ( ll.Count > 0 )  
      {
         Console.WriteLine( "The item in the list is {0}.",
 ll.First.Value );
         Console.WriteLine( "The item in the list is {0}.",
 ll.Last.Value );

         Console.WriteLine( "The LinkedList contains:" );
         foreach ( String s in ll )
            Console.WriteLine( "   {0}", s);
      }
      else  
      {
         Console.WriteLine("The LinkedList is empty.");
      }
   }
}

/* This code produces the following output.

The first item in the list is red.
The last item in the list is orange.
The LinkedList contains:
   red
   orange
   yellow
   orange
*/
#using <System.dll>

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

void main()
{
   // Create and initialize a new LinkedList.
   LinkedList< String^ > ^ ll = gcnew LinkedList< String^ >;
   ll->AddLast( L"red" );
   ll->AddLast( L"orange" );
   ll->AddLast( L"yellow" );
   ll->AddLast( L"orange" );
   
   // Display the contents of the LinkedList.
   if ( ll->Count > 0 )
   {
      Console::WriteLine( L"The first item in the list is
 {0}.", ll->First->Value );
      Console::WriteLine( L"The last item in the list is
 {0}.", ll->Last->Value );
      Console::WriteLine( L"The LinkedList contains:" );

      for each (String^ s in ll)
      {
         Console::WriteLine( L"   {0}", s );
      }
   }
   else
   {
      Console::WriteLine( L"The LinkedList is empty." );
   }
}

/* This code produces the following output.

The first item in the list is red.
The last item in the list is orange.
The LinkedList contains:
   red
   orange
   yellow
   orange
*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
LinkedList ジェネリック クラス
LinkedList メンバ
System.Collections.Generic 名前空間

LinkedList コンストラクタ (ジェネリック IEnumerable)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定した IEnumerable からコピーした要素を格納し、コピーされる要素の数を格納できるだけの容量を備えた、LinkedList クラスの新しいインスタンスを初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    collection As IEnumerable(Of T) _
)
Dim collection As IEnumerable(Of
 T)

Dim instance As New LinkedList(Of
 T)(collection)
public LinkedList (
    IEnumerable<T> collection
)
public:
LinkedList (
    IEnumerable<T>^ collection
)
public LinkedList (
    IEnumerable<T> collection
)
public function LinkedList (
    collection : IEnumerable<T>
)

パラメータ

collection

新しい LinkedList に要素がコピーされた IEnumerable。

例外例外
例外の種類条件

ArgumentNullException

collection が null 参照 (Visual Basic では Nothing) です。

解説解説

LinkedList は、null 参照 (Visual Basic では Nothing) を参照型に対して有効な Value として受け取り、値の重複を許可します。

collection に要素がない場合、新しい LinkedList は空で、First プロパティと Last プロパティには null 参照 (Visual Basic では Nothing) が格納されます。

このコンストラクタは O(n) 操作です。ここで、n は collection 内の要素数です。

使用例使用例

LinkedList(ジェネリック IEnumerable) コンストラクタのコード例および出力を次に示します。このコード例では、文字列の配列を作成し、その文字列の配列をコンストラクタに渡すことによって、LinkedList を作成し、データを読み込みます。

このコード例および出力は、LinkedList クラスのトピックで取り上げている例の一部分です。

        Dim words() As String =
 _
            { "the", "fox",
 "jumped", "over",
 "the", "dog" }
        Dim sentence As New
 LinkedList(Of String)(words)
        Display(sentence)

        Console.WriteLine("sentence.Contains(""jumped"")
 = {0}", _
            sentence.Contains("jumped"))
<br /><span space="preserve">...</span><br
 />'the fox jumped over the dog
'sentence.Contains("jumped") = True
        string[] words = 
            {"the", "fox", "jumped", "over",
 "the", "dog"};
        LinkedList<string> sentence = new
 LinkedList<string>(words);
        Display(sentence);

        Console.WriteLine("sentence.Contains(\"jumped\") = {0}",
 
            sentence.Contains("jumped"));
<br /><span space="preserve">...</span><br />//the
 fox jumped over the dog
//sentence.Contains("jumped") = True
    array<String^>^ words = 
        {"the", "fox", "jumped", "over",
 "the", "dog"};
    LinkedList<String^>^ sentence = 
        gcnew LinkedList<String^>((IEnumerable<String^>^) words);
    Display(sentence);

    Console::WriteLine("sentence->Contains(\"jumped\") = {0}",
 
        sentence->Contains("jumped"));
<br /><span space="preserve">...</span><br />//the
 fox jumped over the dog
//sentence->Contains("jumped") = True
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
LinkedList ジェネリック クラス
LinkedList メンバ
System.Collections.Generic 名前空間

LinkedList コンストラクタ

LinkedList クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
LinkedList () LinkedList クラスの新しい空のインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

LinkedList (ジェネリック IEnumerable) 指定した IEnumerable からコピーした要素を格納し、コピーされる要素の数を格納できるだけの容量を備えた、LinkedList クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

LinkedList (SerializationInfo, StreamingContext) 指定した SerializationInfo と StreamingContext を使用して、シリアル化可能な LinkedList クラスの新しいインスタンスを初期化します。
参照参照

関連項目

LinkedList ジェネリック クラス
LinkedList メンバ
System.Collections.Generic 名前空間

LinkedList コンストラクタ (SerializationInfo, StreamingContext)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定した SerializationInfo と StreamingContext を使用して、シリアル化可能な LinkedList クラスの新しいインスタンスを初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New LinkedList(Of
 T)(info, context)
protected LinkedList (
    SerializationInfo info,
    StreamingContext context
)
protected:
LinkedList (
    SerializationInfo^ info, 
    StreamingContext context
)
protected LinkedList (
    SerializationInfo info, 
    StreamingContext context
)
protected function LinkedList (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

LinkedList をシリアル化するために必要な情報を格納している System.Runtime.Serialization.SerializationInfo オブジェクト。

context

LinkedList に関連付けられているシリアル化ストリームのソースおよびデスティネーションを格納している System.Runtime.Serialization.StreamingContext オブジェクト。

解説解説

LinkedList は、null 参照 (Visual Basic では Nothing) を参照型に対して有効な Value として受け取り、値の重複を許可します。

LinkedList が空の場合、First プロパティと Last プロパティには null 参照 (Visual Basic では Nothing) が格納されます。

このコンストラクタは O(n) 操作です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
LinkedList ジェネリック クラス
LinkedList メンバ
System.Collections.Generic 名前空間
System.Runtime.Serialization

LinkedList ジェネリック クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

二重にリンクされたリストを表します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(False)> _
Public Class LinkedList(Of
 T)
    Implements ICollection(Of T), IEnumerable(Of
 T), _
    ICollection, IEnumerable, ISerializable, IDeserializationCallback
Dim instance As LinkedList(Of
 T)
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
public class LinkedList<T> : ICollection<T>,
 IEnumerable<T>, 
    ICollection, IEnumerable, ISerializable, IDeserializationCallback
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
generic<typename T>
public ref class LinkedList : ICollection<T>,
 IEnumerable<T>, 
    ICollection, IEnumerable, ISerializable, IDeserializationCallback
J# では、ジェネリックな型およびメソッドは使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッドは使用できません。

型パラメータ

T

リンク リストの要素の型を示します。

解説解説

LinkedList は、汎用のリンク リストです。これは、.NET Framework の他のコレクション クラスと同様に、列挙子をサポートし、ICollection インターフェイスを実装しています。

LinkedList は、LinkedListNode 型の個別のノードを持つ真のリンク リストであるため、挿入および削除は O(1) 操作になります。参照型を格納しているリストは、ノードとその値が同時に作成される場合、より効率的に実行されます。基になるノードが公開されているため、GC ヒープ上の割り当てを行わない O(1) 操作として、ノードを削除し、それらを同じリストまたは別のリストに再挿入できます。リストには内部カウントも維持されるため、Count プロパティの取得は O(1) 操作です。リストがシングル スレッドから使用される場合は、このカウントの一貫性が保たれます。

LinkedList クラスでは、リストを一貫性のない状態にするチェーン、分割、循環参照などの機能はサポートしていません。この設計により、リストの整合性を維持でき、シングル スレッドでの操作では、リストの一貫性が保たれます。LinkedList でマルチスレッドがサポートされているのは、マルチスレッドの読み取り操作の場合だけです。それ以外のマルチスレッド操作の場合は、独自の同期処理を提供する必要があります。

メモメモ

常に、特定の状況でより効率的に実行されるリンク リストや、追加機能のためにプログラミングの安全性を犠牲にするリンク リストが作成される可能性があります。

LinkedList の各ノードは、LinkedListNode 型です。LinkedList は二重にリンクされているため、各ノードは、前方の Next ノードと後方の Previous ノードを指しています。ノードにはリストへのリンクがあるため、そのリストに対して無効な操作 (実際には別のリストに存在するノードを削除しようとするなど) を行っても、リストは矛盾した状態にはなりません。

LinkedList は、null 参照 (Visual Basic では Nothing) を参照型に対して有効な Value として受け取り、値の重複を許可します。

LinkedList が空の場合、First プロパティと Last プロパティには null 参照 (Visual Basic では Nothing) が格納されます。

使用例使用例

LinkedList クラスが備える多数の機能を次の例で示します。このコード例では、文字列の配列を作成し、その文字列の配列を LinkedList(ジェネリック IEnumerable) コンストラクタに渡すことによって、文字列の LinkedList を作成し、データを読み込みます。

また、LinkedList クラスのプロパティおよびメソッドを使用して結果のリンク リストを操作し、操作の結果を表示します。

Imports System
Imports System.Text
Imports System.Collections.Generic

Public Class Example

    Public Shared Sub Main()

        Dim words() As String
 = _
            { "the", "fox",
 "jumped", "over",
 "the", "dog" }
        Dim sentence As New
 LinkedList(Of String)(words)
        Display(sentence)

        Console.WriteLine("sentence.Contains(""jumped"")
 = {0}", _
            sentence.Contains("jumped"))

        ' Add the word "today" to the beginning of the linked
 list.
        ' Remove the new node, and add it to the end of the list.
        sentence.AddFirst("today")
        Display(sentence)

        Dim mark1 As LinkedListNode(Of
 String) = sentence.First
        sentence.RemoveFirst()
        sentence.AddLast(mark1)
        Display(sentence)

        sentence.RemoveLast()
        sentence.AddLast("yesterday")
        Display(sentence)

        mark1 = sentence.Last
        sentence.RemoveLast()
        sentence.AddFirst(mark1)
        Display(sentence)

        sentence.RemoveFirst()

        Dim current As LinkedListNode(Of
 String) = _
            sentence.FindLast("the")
        DisplayNode(current)

        sentence.AddAfter(current, "old")
        sentence.AddAfter(current, "lazy")
        DisplayNode(current)

        current = sentence.Find("fox")
        DisplayNode(current)

        sentence.AddBefore(current, "quick")
        sentence.AddBefore(current, "brown")
        DisplayNode(current)

        ' Keep a reference to the current node, "fox", and
 to the
        ' previous node in the list. Use the Find method to locate
        ' the node containing the value "dog". Show the position.
        mark1 = current
        Dim mark2 As LinkedListNode(Of
 String) = current.Previous
        current = sentence.Find("dog")
        DisplayNode(current)

        ' The AddBefore method throws an InvalidOperationException
        ' if you try to add a node that already belongs to a list.
        Try
            sentence.AddBefore(current, mark1)
        Catch ex As InvalidOperationException
            Console.WriteLine("Exception message: {0}",
 ex.Message)
        End Try

        ' Remove the node referred to by mark1, and add it before 
        ' the node referred to by current. Show the sentence, 
        ' highlighting the position of the node referred to by
        ' current.
        sentence.Remove(mark1)
        sentence.AddBefore(current, mark1)
        DisplayNode(current)

        ' Remove the node referred to by current. If you try to show
        ' its position now, the DisplayNode method prints a message.
        ' Add the node after the node referred to by mark2, and 
        ' display the sentence, highlighting current.
        sentence.Remove(current)
        DisplayNode(current)
        sentence.AddAfter(mark2, current)
        DisplayNode(current)

        ' The Remove method finds and removes the first node that 
        ' that has the specified value.
        sentence.Remove("old")
        Display(sentence)

        ' 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)

        ' Create an array, specifying a size one less than the size
        ' of the linked list, because Visual Basic allocates one 
        ' more element than you specify.
        Console.WriteLine(vbLf & "Copy the list to an array.")
        Dim sArray(sentence.Count - 1) As String
 
        sentence.CopyTo(sArray, 0)

        For Each s As String
 In sArray
            Console.WriteLine(s)
        Next

        ' Release all the nodes.
        sentence.Clear()

    End Sub

    Private Shared Sub Display(ByVal
 words As LinkedList(Of String))
        For Each word As
 String In words
            Console.Write(word & " ")
        Next
        Console.WriteLine()
    End Sub
    
    Private Shared Sub DisplayNode(ByVal
 node As LinkedListNode(Of String))
        If node.List Is Nothing
 Then
            Console.WriteLine("Node ""{0}""
 is not in a list.", node.Value)
            Return
        End If

        Dim result As New
 StringBuilder ("(" & node.Value & ")")
        Dim nodeP As LinkedListNode(Of
 String) = node.Previous

        While nodeP IsNot Nothing
            result.Insert(0, nodeP.Value & " ")
            nodeP = nodeP.Previous
        End While

        node = node.Next
        While node IsNot Nothing
            result.Append(" " & node.Value)
            node = node.Next
        End While

        Console.WriteLine(result)
    End Sub

End Class

'This code example produces the following output:
'
'the fox jumped over the dog
'sentence.Contains("jumped") = True
'today the fox jumped over the dog
'the fox jumped over the dog today
'the fox jumped over the dog yesterday
'yesterday the fox jumped over the dog
'the fox jumped over (the) dog
'the fox jumped over (the) lazy old dog
'the (fox) jumped over the lazy old dog
'the quick brown (fox) jumped over the lazy old dog
'the quick brown fox jumped over the lazy old (dog)
'Exception message: The LinkedList node belongs a LinkedList.
'the quick brown jumped over the lazy old fox (dog)
'Node "dog" is not in a list.
'the quick brown (dog) jumped over the lazy old fox
'the quick brown dog jumped over the lazy fox
'the quick brown dog jumped over the lazy rhinoceros
'
'Copy the list to an array.
'the
'quick
'brown
'dog
'jumped
'over
'the
'lazy
'rhinoceros
using System;
using System.Text;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        string[] words = 
            {"the", "fox", "jumped", "over",
 "the", "dog"};
        LinkedList<string> sentence = new
 LinkedList<string>(words);
        Display(sentence);

        Console.WriteLine("sentence.Contains(\"jumped\") = {0}",
 
            sentence.Contains("jumped"));

        // Add the word "today" to the beginning of the linked
 list.
        // Remove the new node, and add it to the end of the list.
        sentence.AddFirst("today");
        Display(sentence);

        LinkedListNode<string> mark1 = sentence.First;
        sentence.RemoveFirst();
        sentence.AddLast(mark1);
        Display(sentence);

        sentence.RemoveLast();
        sentence.AddLast("yesterday");
        Display(sentence);

        mark1 = sentence.Last;
        sentence.RemoveLast();
        sentence.AddFirst(mark1);
        Display(sentence);

        sentence.RemoveFirst();

        LinkedListNode<string> current = sentence.FindLast("the");
        DisplayNode(current);

        sentence.AddAfter(current, "old");
        sentence.AddAfter(current, "lazy");
        DisplayNode(current);

        current = sentence.Find("fox");
        DisplayNode(current);

        sentence.AddBefore(current, "quick");
        sentence.AddBefore(current, "brown");
        DisplayNode(current);

        // Keep a reference to the current node, "fox", and
 to the
        // previous node in the list. Use the Find method to locate
        // the node containing the value "dog". Show the position.
        mark1 = current;
        LinkedListNode<string> mark2 = current.Previous;
        current = sentence.Find("dog");
        DisplayNode(current);

        // The AddBefore method throws an InvalidOperationException
        // if you try to add a node that already belongs to a list.
        try
        {
            sentence.AddBefore(current, mark1);
        }
        catch(InvalidOperationException ex)
        {
            Console.WriteLine("Exception message: {0}", ex.Message);
        }

        // Remove the node referred to by mark1, and add it before 
        // the node referred to by current. Show the sentence, 
        // highlighting the position of the node referred to by
        // current.
        sentence.Remove(mark1);
        sentence.AddBefore(current, mark1);
        DisplayNode(current);

        // Remove the node referred to by current. If you try to show
        // its position now, the DisplayNode method prints a message.
        // Add the node after the node referred to by mark2, and 
        // display the sentence, highlighting current.
        sentence.Remove(current);
        DisplayNode(current);
        sentence.AddAfter(mark2, current);
        DisplayNode(current);

        // The Remove method finds and removes the first node that 
        // that has the specified value.
        sentence.Remove("old");
        Display(sentence);

        // 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);

        // Create an array with the same number of elements as the
        // linked list.
        Console.WriteLine("\nCopy the list to an array.");
        string[] sArray = new string[sentence.Count];
        sentence.CopyTo(sArray, 0);

        foreach( string s in
 sArray )
        {
            Console.WriteLine(s);
        }

        // Release all the nodes.
        sentence.Clear();

    }

    private static void
 Display(LinkedList<string> words)
    {
        foreach( string word in
 words )
        {
            Console.Write(word + " ");
        }
        Console.WriteLine();
    }
    
    private static void
 DisplayNode(LinkedListNode<string> node)
    {
        if (node.List==null)
        {
            Console.WriteLine("Node \"{0}\" is not in
 a list.", 
                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);
    }
}

//This code example produces the following output:
//
//the fox jumped over the dog
//sentence.Contains("jumped") = True
//today the fox jumped over the dog
//the fox jumped over the dog today
//the fox jumped over the dog yesterday
//yesterday the fox jumped over the dog
//the fox jumped over (the) dog
//the fox jumped over (the) lazy old dog
//the (fox) jumped over the lazy old dog
//the quick brown (fox) jumped over the lazy old dog
//the quick brown fox jumped over the lazy old (dog)
//Exception message: The LinkedList node belongs a LinkedList.
//the quick brown jumped over the lazy old fox (dog)
//Node "dog" is not in a list.
//the quick brown (dog) jumped over the lazy old fox
//the quick brown dog jumped over the lazy fox
//the quick brown dog jumped over the lazy rhinoceros
//
//Copy the list to an array.
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros
#using <System.dll>

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

void Display(LinkedList<String^>^ words)
{
    for each( String^ word in words )
    {
        Console::Write(word + " ");
    }
    Console::WriteLine();
};
    
void DisplayNode(LinkedListNode<String^>^ node)
{
    if (node->List == nullptr)
    {
        Console::WriteLine("Node \"{0}\" is not in
 a list.", 
            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);
};

void main()
{
    array<String^>^ words = 
        {"the", "fox", "jumped", "over",
 "the", "dog"};
    LinkedList<String^>^ sentence = 
        gcnew LinkedList<String^>((IEnumerable<String^>^) words);
    Display(sentence);

    Console::WriteLine("sentence->Contains(\"jumped\") = {0}",
 
        sentence->Contains("jumped"));

    // Add the word "today" to the beginning of the linked
 list.
    // Remove the new node, and add it to the end of the list.
    sentence->AddFirst("today");
    Display(sentence);

    LinkedListNode<String^>^ mark1 = sentence->First;
    sentence->RemoveFirst();
    sentence->AddLast(mark1);
    Display(sentence);

    sentence->RemoveLast();
    sentence->AddLast("yesterday");
    Display(sentence);

    mark1 = sentence->Last;
    sentence->RemoveLast();
    sentence->AddFirst(mark1);
    Display(sentence);

    sentence->RemoveFirst();

    LinkedListNode<String^>^ current = sentence->FindLast("the");
    DisplayNode(current);

    sentence->AddAfter(current, "old");
    sentence->AddAfter(current, "lazy");
    DisplayNode(current);

    current = sentence->Find("fox");
    DisplayNode(current);

    sentence->AddBefore(current, "quick");
    sentence->AddBefore(current, "brown");
    DisplayNode(current);

    // Keep a reference to the current node, "fox", and to
 the
    // previous node in the list. Use the Find method to locate
    // the node containing the value "dog". Show the position.
    mark1 = current;
    LinkedListNode<String^>^ mark2 = current->Previous;
    current = sentence->Find("dog");
    DisplayNode(current);

    // The AddBefore method throws an InvalidOperationException
    // if you try to add a node that already belongs to a list.
    try
    {
        sentence->AddBefore(current, mark1);
    }
    catch(InvalidOperationException^ ex)
    {
        Console::WriteLine("Exception message: {0}", ex->Message);
    }

    // Remove the node referred to by mark1, and add it before 
    // the node referred to by current. Show the sentence, 
    // highlighting the position of the node referred to by
    // current.
    sentence->Remove(mark1);
    sentence->AddBefore(current, mark1);
    DisplayNode(current);

    // Remove the node referred to by current. If you try to show
    // its position now, the DisplayNode method prints a message.
    // Add the node after the node referred to by mark2, and 
    // display the sentence, highlighting current.
    sentence->Remove(current);
    DisplayNode(current);
    sentence->AddAfter(mark2, current);
    DisplayNode(current);

    // The Remove method finds and removes the first node that 
    // that has the specified value.
    sentence->Remove("old");
    Display(sentence);

    // 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);

    // Create an array with the same number of elements as the
    // linked list.
    Console::WriteLine("\nCopy the list to an array.");
    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();
}

//This code example produces the following output:
//
//the fox jumped over the dog
//sentence->Contains("jumped") = True
//today the fox jumped over the dog
//the fox jumped over the dog today
//the fox jumped over the dog yesterday
//yesterday the fox jumped over the dog
//the fox jumped over (the) dog
//the fox jumped over (the) lazy old dog
//the (fox) jumped over the lazy old dog
//the quick brown (fox) jumped over the lazy old dog
//the quick brown fox jumped over the lazy old (dog)
//Exception message: The LinkedList node belongs a LinkedList.
//the quick brown jumped over the lazy old fox (dog)
//Node "dog" is not in a list.
//the quick brown (dog) jumped over the lazy old fox
//the quick brown dog jumped over the lazy fox
//the quick brown dog jumped over the lazy rhinoceros
//
//Copy the list to an array.
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros
継承階層継承階層
System.Object
  System.Collections.Generic.LinkedList
スレッド セーフスレッド セーフ

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバがスレッド セーフになるかどうかは保証されていません。

コレクションが変更されない限り、LinkedList では、複数の読み込み操作が同時に発生しても問題ありません。ただし、コレクションの列挙処理は、本質的にはスレッド セーフな処理ではありません。まれに書き込みアクセスによって列挙処理で競合が発生する場合、列挙処理が完了するまでコレクションをロックする必要があります。コレクションに対し複数のスレッドがアクセスして読み取りや書き込みを行うことができるようにするには、独自に同期化を実装する必要があります。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
LinkedList メンバ
System.Collections.Generic 名前空間
LinkedListNode

LinkedList プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Last LinkedList ノードの最後のノードを取得します。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセスを同期するために使用できるオブジェクトを取得します。
参照参照

関連項目

LinkedList ジェネリック クラス
System.Collections.Generic 名前空間
LinkedListNode

LinkedList メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド AddAfter オーバーロードされます。 LinkedList 内の既存のノードの後に新しいノードまたは値を追加します。
パブリック メソッド AddBefore オーバーロードされます。 LinkedList 内の既存のノードの前に新しいノードまたは値を追加します。
パブリック メソッド AddFirst オーバーロードされます。 LinkedList の先頭に新しいノードまたは値を追加します。
パブリック メソッド AddLast オーバーロードされます。 LinkedList の末尾に新しいノードまたは値を追加します。
パブリック メソッド Clear LinkedList からすべてのノードを削除します。
パブリック メソッド Contains ある値が LinkedList 内に存在するかどうかを判断します。
パブリック メソッド CopyTo LinkedList 全体を互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Find 指定した値を含む最初のノードを検索します。
パブリック メソッド FindLast 指定した値を含む最後のノードを検索します。
パブリック メソッド GetEnumerator LinkedList を反復処理する列挙子を返します。
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetObjectData System.Runtime.Serialization.ISerializable インターフェイスを実装し、LinkedList インスタンスをシリアル化するために必要なデータを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド OnDeserialization System.Runtime.Serialization.ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントを発生させます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remove オーバーロードされます。 最初に出現するノードまたは値を LinkedList から削除します。
パブリック メソッド RemoveFirst LinkedList の先頭にあるノードを削除します。
パブリック メソッド RemoveLast LinkedList の末尾にあるノードを削除します。
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.ICollection<T>.Add ICollection の末尾にアイテムを追加します。
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクションを反復処理する列挙子を返します。
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクションとしてリンク リストを反復処理する列挙子を返します。
参照参照

関連項目

LinkedList ジェネリック クラス
System.Collections.Generic 名前空間
LinkedListNode

LinkedList メンバ

二重にリンクされたリストを表します。

LinkedList ジェネリック型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Last LinkedList ノードの最後のノードを取得します。
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド AddAfter オーバーロードされます。 LinkedList 内の既存のノードの後に新しいノードまたは値を追加します。
パブリック メソッド AddBefore オーバーロードされます。 LinkedList 内の既存のノードの前に新しいノードまたは値を追加します。
パブリック メソッド AddFirst オーバーロードされます。 LinkedList の先頭に新しいノードまたは値を追加します。
パブリック メソッド AddLast オーバーロードされます。 LinkedList の末尾に新しいノードまたは値を追加します。
パブリック メソッド Clear LinkedList からすべてのノードを削除します。
パブリック メソッド Contains ある値が LinkedList 内に存在するかどうかを判断します。
パブリック メソッド CopyTo LinkedList 全体を互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド Find 指定した値を含む最初のノードを検索します。
パブリック メソッド FindLast 指定した値を含む最後のノードを検索します。
パブリック メソッド GetEnumerator LinkedList を反復処理する列挙子を返します。
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetObjectData System.Runtime.Serialization.ISerializable インターフェイスを実装し、LinkedList インスタンスをシリアル化するために必要なデータを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド OnDeserialization System.Runtime.Serialization.ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントを発生させます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remove オーバーロードされます。 最初に出現するノードまたは値を LinkedList から削除します。
パブリック メソッド RemoveFirst LinkedList の先頭にあるノードを削除します。
パブリック メソッド RemoveLast LinkedList の末尾にあるノードを削除します。
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.ICollection<T>.Add ICollection の末尾にアイテムを追加します。
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクションを反復処理する列挙子を返します。
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクションとしてリンク リストを反復処理する列挙子を返します。
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセスを同期するために使用できるオブジェクトを取得します。
参照参照

関連項目

LinkedList ジェネリック クラス
System.Collections.Generic 名前空間
LinkedListNode

「Linked list」の例文・使い方・用例・文例

Weblio日本語例文用例辞書はプログラムで機械的に例文を生成しているため、不適切な項目が含まれていることもあります。ご了承くださいませ。


英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「LinkedList」の関連用語

LinkedListのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



LinkedListのページの著作権

   
IT用語辞典バイナリIT用語辞典バイナリ
Copyright © 2005-2026 Weblio 辞書 IT用語辞典バイナリさくいん。 この記事は、IT用語辞典バイナリの【連結リスト】の記事を利用しております。
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.
Tanaka Corpusのコンテンツは、特に明示されている場合を除いて、次のライセンスに従います:
 Creative Commons Attribution (CC-BY) 2.0 France.
この対訳データはCreative Commons Attribution 3.0 Unportedでライセンスされています。
浜島書店 Catch a Wave
Copyright © 1995-2026 Hamajima Shoten, Publishers. All rights reserved.
株式会社ベネッセコーポレーション株式会社ベネッセコーポレーション
Copyright © Benesse Holdings, Inc. All rights reserved.
研究社研究社
Copyright (c) 1995-2026 Kenkyusha Co., Ltd. All rights reserved.
日本語WordNet日本語WordNet
日本語ワードネット1.1版 (C) 情報通信研究機構, 2009-2010 License All rights reserved.
WordNet 3.0 Copyright 2006 by Princeton University. All rights reserved. License
日外アソシエーツ株式会社日外アソシエーツ株式会社
Copyright (C) 1994- Nichigai Associates, Inc., All rights reserved.
「斎藤和英大辞典」斎藤秀三郎著、日外アソシエーツ辞書編集部編
EDRDGEDRDG
This page uses the JMdict dictionary files. These files are the property of the Electronic Dictionary Research and Development Group, and are used in conformance with the Group's licence.

©2026 GRAS Group, Inc.RSS