Question: OurList Class IN C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace MyPrograms { public class OurList : ICollection ,

 OurList Class IN C# using System; using System.Collections.Generic; using System.Linq; using

OurList Class IN C#

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections;

namespace MyPrograms { public class OurList : ICollection, IEnumerable { private class Node { public T Data { get; set; } public Node Next { get; set; } public Node(T d = default(T), Node node = null) { Data = d; Next = node; } } private Node first; public OurList() { first = null; } public void Clear() { first = null; } public bool IsEmpty() { return first == null; } public void AddFront(T value) { first = new Node(value, first); } public void RemoveFirst() { if (first != null) first = first.Next; } public int Count { get { int count = 0; Node pTmp = first; while (pTmp != null) { count++; pTmp = pTmp.Next; } return count; } } public void AddLast(T value) { if (first == null) AddFront(value); else { Node mTmp = first; while (mTmp.Next != null) mTmp = mTmp.Next;

mTmp.Next = new Node(value, null); } } public void RemoveLast() { if (first == null) return; else if (first.Next == null) RemoveFirst(); else { Node pTmp = first; while (pTmp.Next.Next != null) pTmp = pTmp.Next;

pTmp.Next = null; } } public void InsertAt(int index, T value) { if (index >= 0 && index

pTmp.Next = new Node(value, pTmp.Next); } } else throw new ArgumentOutOfRangeException(); } public void RemoveAt(int index) { if (index >= 0 && index GetEnumerator() { Node pTmp = first; while (pTmp != null) { yield return pTmp.Data; pTmp = pTmp.Next; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public override string ToString() { if (IsEmpty() == true) return string.Empty; StringBuilder returnString = new StringBuilder(); foreach (T item in this) { if (returnString.Length > 0) returnString.Append(":"); returnString.Append(item); } return returnString.ToString(); } } }

Linked List Add a method to the OurList class that accepts a list and counts how many items are on this list and are not on the list that is passed into this method. Assume none of the lists contain duplicates. Make sure the method is efficient. Example: List1: 5, 17, 10, 9, 2 List2: 9, 17, 3,8 Result: when method is called using List1 and method is passed List2, the method returns 3 since 5, 10, and 2 are on List1 and not on List2 when method is called using List2 and method is passed List1, the method returns 2 since 3 and 8 are on List2 and not on List1 Linked List Add a method to the OurList class that accepts a list and counts how many items are on this list and are not on the list that is passed into this method. Assume none of the lists contain duplicates. Make sure the method is efficient. Example: List1: 5, 17, 10, 9, 2 List2: 9, 17, 3,8 Result: when method is called using List1 and method is passed List2, the method returns 3 since 5, 10, and 2 are on List1 and not on List2 when method is called using List2 and method is passed List1, the method returns 2 since 3 and 8 are on List2 and not on List1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!