Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions in C# Add a ToArray method to OurList class below that returns an array containing all of the elements in this list in proper

Instructions in C# Add a ToArray method to OurList class below that returns an array containing all of the elements in this list in proper sequence (from first to last element). Test your method in a main routine in a different class (e..g. don't put a main routine in the list class). Do not turn in the code below. Turn in your ToArray method and the main routine from the other class. 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 youve 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. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LinkListExample { public class OurList { private class OurListNode { public T Data { get; set; } public OurListNode Next { get; set; } public OurListNode(T paramData = default(T), OurListNode paramNext = null) { this.Data = paramData; this.Next = paramNext; } } private OurListNode first; public OurList() { first = null; } public void Clear() // shown in class notes { first = null; } public void AddFirst(T data) // shown in class notes { this.first = new OurListNode(data, this.first); } public void RemoveFirst() // shown in class notes { if (first != null) first = first.Next; } public void AddLast(T data) // shown in class notes { if (first == null) AddFirst(data); else { OurListNode pTmp = first; while (pTmp.Next != null) pTmp = pTmp.Next; pTmp.Next = new OurListNode(data, null); } } public void RemoveLast() // shown in class notes { if (first == null) return; else if (first.Next == null) RemoveFirst(); else { OurListNode pTmp = first; while (pTmp.Next != null && pTmp.Next.Next != null) pTmp = pTmp.Next; pTmp.Next = null; } } public void Display() // shown in class notes { OurListNode pTmp = first; while (pTmp != null) { Console.Write("{0}, ", pTmp.Data); pTmp = pTmp.Next; } Console.WriteLine(); } public bool IsEmpty() // shown in class notes { if (first == null) return true; else return false; } } }

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

Step: 3

blur-text-image

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions