Java LinkedList get node

LinkedListNode.Next Property

  • Reference
Is this page helpful?

Please rate your experience

Yes No
Any additional feedback?

Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy.

Submit

Thank you.

Definition

Namespace: System.Collections.Generic Assembly:System.Collections.dll Assembly:System.dll Assembly:netstandard.dll

Important

Some information relates to prerelease product that may be substantially modified before its released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

In this article

Gets the next node in the LinkedList.

public: property System::Collections::Generic::LinkedListNode ^ Next { System::Collections::Generic::LinkedListNode ^ get[]; }; public System.Collections.Generic.LinkedListNode Next { get; } public System.Collections.Generic.LinkedListNode? Next { get; } member this.Next : System.Collections.Generic.LinkedListNodeAddFirst[ "red" ]; ll->AddLast[ "yellow" ]; Console::WriteLine[ "After adding red and yellow ...." ]; DisplayProperties[ lln ]; } static void DisplayProperties[ LinkedListNode^ lln ] { if [ lln->List == nullptr ] Console::WriteLine[ " Node is not linked." ]; else Console::WriteLine[ " Node belongs to a linked list with {0} elements.", lln->List->Count ]; if [ lln->Previous == nullptr ] Console::WriteLine[ " Previous node is null." ]; else Console::WriteLine[ " Value of previous node: {0}", lln->Previous->Value ]; Console::WriteLine[ " Value of current node: {0}", lln->Value ]; if [ lln->Next == nullptr ] Console::WriteLine[ " Next node is null." ]; else Console::WriteLine[ " Value of next node: {0}", lln->Next->Value ]; Console::WriteLine[]; } }; int main[] { GenericCollection::Main[]; } /* This code produces the following output. After creating the node .... Node is not linked. Previous node is null. Value of current node: orange Next node is null. After adding the node to the empty LinkedList .... Node belongs to a linked list with 1 elements. Previous node is null. Value of current node: orange Next node is null. After adding red and yellow .... Node belongs to a linked list with 3 elements. Value of previous node: red Value of current node: orange Value of next node: yellow */ using System; using System.Collections.Generic; public class GenericCollection { public static void Main[] { // Create a new LinkedListNode of type String and displays its properties. LinkedListNode lln = new LinkedListNode[ "orange" ]; Console.WriteLine[ "After creating the node ...." ]; DisplayProperties[ lln ]; // Create a new LinkedList. LinkedList ll = new LinkedList[]; // Add the "orange" node and display its properties. ll.AddLast[ lln ]; Console.WriteLine[ "After adding the node to the empty LinkedList ...." ]; DisplayProperties[ lln ]; // Add nodes before and after the "orange" node and display the "orange" node's properties. ll.AddFirst[ "red" ]; ll.AddLast[ "yellow" ]; Console.WriteLine[ "After adding red and yellow ...." ]; DisplayProperties[ lln ]; } public static void DisplayProperties[ LinkedListNode lln ] { if [ lln.List == null ] Console.WriteLine[ " Node is not linked." ]; else Console.WriteLine[ " Node belongs to a linked list with {0} elements.", lln.List.Count ]; if [ lln.Previous == null ] Console.WriteLine[ " Previous node is null." ]; else Console.WriteLine[ " Value of previous node: {0}", lln.Previous.Value ]; Console.WriteLine[ " Value of current node: {0}", lln.Value ]; if [ lln.Next == null ] Console.WriteLine[ " Next node is null." ]; else Console.WriteLine[ " Value of next node: {0}", lln.Next.Value ]; Console.WriteLine[]; } } /* This code produces the following output. After creating the node .... Node is not linked. Previous node is null. Value of current node: orange Next node is null. After adding the node to the empty LinkedList .... Node belongs to a linked list with 1 elements. Previous node is null. Value of current node: orange Next node is null. After adding red and yellow .... Node belongs to a linked list with 3 elements. Value of previous node: red Value of current node: orange Value of next node: yellow */ Imports System.Collections.Generic Public Class GenericCollection Public Shared Sub Main[] ' Create a new LinkedListNode of type String and displays its properties. Dim lln As New LinkedListNode[Of String]["orange"] Console.WriteLine["After creating the node ...."] DisplayProperties[lln] ' Create a new LinkedList. Dim ll As New LinkedList[Of String] ' Add the "orange" node and display its properties. ll.AddLast[lln] Console.WriteLine["After adding the node to the empty LinkedList ...."] DisplayProperties[lln] ' Add nodes before and after the "orange" node and display the "orange" node's properties. ll.AddFirst["red"] ll.AddLast["yellow"] Console.WriteLine["After adding red and yellow ...."] DisplayProperties[lln] End Sub Public Shared Sub DisplayProperties[lln As LinkedListNode[Of String]] If lln.List Is Nothing Then Console.WriteLine[" Node is not linked."] Else Console.WriteLine[" Node belongs to a linked list with {0} elements.", lln.List.Count] End If If lln.Previous Is Nothing Then Console.WriteLine[" Previous node is null."] Else Console.WriteLine[" Value of previous node: {0}", lln.Previous.Value] End If Console.WriteLine[" Value of current node: {0}", lln.Value] If lln.Next Is Nothing Then Console.WriteLine[" Next node is null."] Else Console.WriteLine[" Value of next node: {0}", lln.Next.Value] End If Console.WriteLine[] End Sub End Class 'This code produces the following output. ' 'After creating the node .... ' Node is not linked. ' Previous node is null. ' Value of current node: orange ' Next node is null. ' 'After adding the node to the empty LinkedList .... ' Node belongs to a linked list with 1 elements. ' Previous node is null. ' Value of current node: orange ' Next node is null. ' 'After adding red and yellow .... ' Node belongs to a linked list with 3 elements. ' Value of previous node: red ' Value of current node: orange ' Value of next node: yellow

Applies to

Video liên quan

Chủ Đề