Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ,

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago