Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

image text in transcribed 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 T[] ToArray() { // complete this method, turn in just this method } 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; } } } 
Complete the 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 Toray method and the main routine from the other class

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

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions