Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C#: Add a Contains method to the OurList class below that returns true if a v

ID: 3902979 • Letter: I

Question

In C#:

Add a Contains method to the OurList class below that returns true if a value is found in the list or false if the value is not found in the list. The value is passed into the method.

Do not turn in the code below. Turn in your method and the main routine testing your method.

Put all of your code in a single text file (extension is .txt). If, as part of the assignment, you have been provided with some code, do not turn in this code unless you’ve made a change to the code. As easy way to do this is run Notepad, then copy from Visual Studio into Notepad. I will not grade zip files unless the assignment specifically ask for a zip file.

Explanation / Answer

public void Contains(T data) // shown in class notes
{
OurListNode<T> pTmp = first;
while (pTmp != null)
{
if(data==pTmp.Data)
return true;
pTmp = pTmp.Next;

}
return false;
}

explaination:

We iterate over the list and compare each and every value with the user input .If found true will be returned if no value is found even after the entire list is compared then false is returned.