InterviewSolution
Saved Bookmarks
| 1. |
Check whether a node is in a Linked List or not |
|
Answer» To check whether a node is in a Linked List or not, the best way is to use the Contains() method. The Contains() method has a parameter that is the value you are SEARCHING for in a Linked List: Contains(Value)The method RETURNS a Boolean Value. If a node is found in the Linked List, TRUE is returned. Let us see an example: using System; using System.Collections.Generic; CLASS Demo { static VOID Main() { string [] devices = {"Smartphones","Smartwatches"}; LinkedList<string> myList = new LinkedList<string>(devices); foreach (var d in myList) { Console.WriteLine(d); } Console.WriteLine("Smartphones in the list?: "+myList.Contains("Smartphones")); } }The OUTPUT: Smartphones Smartwatches Smartphones in the list?: True |
|