Question: //OrderArrayList.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AbstractDataTypes { class OrderedArrayList : ArrayList where T : IComparable { public override
//OrderArrayList.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace AbstractDataTypes { class OrderedArrayList } } public override void Insert(T item) { //step 1 find the location to insert the item for (int i = 0; i = 0) {//found the position to insert //to-do step 2 make a space for the item to insert //to-do step 3 insert the item and increase next by 1 } } } } } //program.cs using System; namespace AbstractDataTypes { class Program { static void ProcessList static void Main(string[] args) { Console.Clear(); Console.WriteLine("--- Unordered List of Integers ---"); ProcessList Console.WriteLine("--- Unordered List of Doubles ---"); ProcessList Console.WriteLine("--- Unordered List of Strings ---"); ProcessList Console.WriteLine("--- Exception testing ---"); UnorderedArrayList Console.Write("{0,25}: ", "Min value of empty list"); try { Console.WriteLine(exceptionList.Min); } catch (Exception e) { Console.WriteLine("\"{0}\"", e.Message); } Console.Write("{0,25}: ", "Max value of empty list"); try { Console.WriteLine(exceptionList.Max); } catch (Exception e) { Console.WriteLine("\"{0}\"", e.Message); } Console.Write("{0,25}: ", "Add 200 items to array"); for (int i = 1; i //UnorderArrayList using System; namespace AbstractDataTypes { class UnorderedArrayList public override T Min { get { if (next == 0) throw new Exception("List is empty"); T min = list[0]; for (int i = 0; i public override T Max { get { if (next == 0) throw new Exception("List is empty"); T max = list[0]; for (int i = 0; i 0) { max = list[i]; } } return max; } } public override void Insert(T item) { if (next == list.Length) { throw new Exception("List is full"); } list[next] = item; next++; } public new void Remove(T item) { for (int i = 0; i // Same as Remove(), just without the break statement public override void RemoveAll(T item) { for (int i = 0; i public override void Sort() { // insertion sort for (int i = 1; i 0 && list[j - 1].CompareTo(list[j]) > 0) { T temp = list[j]; list[j] = list[j - 1]; list[j - 1] = temp; j--; } } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
