Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Find the last node in LinkedList containing the specified value in C#
To find the last node in LinkedList containing the specified value, the code is as follows −
Example
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
list.AddLast(400);
list.AddLast(500);
list.AddLast(300);
list.AddLast(500);
Console.WriteLine("LinkedList elements...");
foreach(int i in list) {
Console.WriteLine(i);
}
LinkedListNode<int> val = list.FindLast(300);
Console.WriteLine("Specified value = "+val.Value);
}
}
Output
This will produce the following output −
LinkedList elements... 100 200 300 400 500 300 500 Specified value = 300
Example
Let us see another example −
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
LinkedList<String> list = new LinkedList<String>();
list.AddLast("One");
list.AddLast("Two");
list.AddLast("Three");
list.AddLast("Four");
list.AddLast("Five");
Console.WriteLine("Elements in LinkedList...");
foreach (string res in list) {
Console.WriteLine(res);
}
LinkedListNode<string> val = list.FindLast("Five");
Console.WriteLine("Specified value = "+val.Value);
}
}
Output
This will produce the following output −
Elements in LinkedList... One Two Three Four Five Specified value = Five
Advertisements
