I have a linked list constructed as follows:
LinkedList<int> linked = new LinkedList<int>();
var array = new int[] { 23, 55, 64, 65 };
foreach (var item in array)
{
linked.AddLast(item);
}
How do I find the index of the number 64?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only way is to check element by element and increase a counter (by “only way”, I am saying that other methods like LINQ need to do the same thing internally).
A hand-written extension method would look something like this:
But it can easily be done using LINQ as @L.B wrote (yielding the same time complexity).