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//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 T Min { get { return list[0]; } } public override T Max { get { if (next

} } 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(IList list, T[] elements, T remove, T removeAll) { Console.Write("{0,25}: ", "Empty"); list.Print(); foreach (T element in elements) { list.Insert(element); } Console.Write("{0,25}: ", "Non-empty"); list.Print(); Console.Write("{0,25}: ", "Min value"); Console.WriteLine(list.Min); Console.Write("{0,25}: ", "Max value"); Console.WriteLine(list.Max); Console.Write("{0,25}: ", "Sorted"); list.Sort(); list.Print(); Console.Write("{0,25}: ", "Remove " + remove.ToString()); list.Remove(remove); list.Print(); Console.Write("{0,25}: ", "Remove every " + removeAll.ToString()); list.RemoveAll(removeAll); list.Print(); }

static void Main(string[] args) { Console.Clear();

Console.WriteLine("--- Unordered List of Integers ---"); ProcessList(new UnorderedArrayList(), new int[] { 5, 12, 2, 29, 2 }, 12, 2); Console.WriteLine();

Console.WriteLine("--- Unordered List of Doubles ---"); ProcessList(new UnorderedArrayList(), new double[] { 5.5, Math.PI, 2.34, 29, 2.34 }, Math.PI, 2.34); Console.WriteLine();

Console.WriteLine("--- Unordered List of Strings ---"); ProcessList(new UnorderedArrayList(), new string[] { "five", "twelve", "two", "twenty nine", "two" }, "twelve", "two"); Console.WriteLine();

Console.WriteLine("--- Exception testing ---"); UnorderedArrayList exceptionList = new 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 : ArrayList where T : IComparable { // Default constructor is unnecessary

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--; } } } } }

Modify the supplied class ArrayListClass the following ways: a) the method remove(), which is inherited from the class ArrayListClass, of the class UnorderedArrayList removes an element from the list by shifting the elements of the list. However, if the element to be removed is at the beginning of the list and the list is fairly large, it could take a lot of computer time to perform the operation. Because the list elements are in no particular order, you could simply remove the element by copying the last element in the list at the position of the item to be removed and reducing the length of the list. Redefine the method remove(), in the class UnorderedArrayList, using this technique. b) the method remove of the class ArrayListClass removes only the first occurrence of an element. Add the method removeAll() to the class ArrayListClass as an abstract method that would remove all occurrences of a given element. (Note that you must add the method removeAll() in the interface ArrayListADT.) Also, write the definition of the method in the class UnorderedArrayList. c) add the methods min and max to the class ArrayListClass, as abstract methods, to return the smallest and largest respective elements in the list. Also, write the definitions of the methods in the class UnorderedArrayList. d) add an insertion sort method that puts the ArrayList| in order. e) Add a new class called OrderedArrayList which will insert objects in ascending order. The OrderedArrayList will inherit the ArrayListClass and you will need to make ArrayListClass work by implementing all the necessary methods. f) Write a program which thoroughly tests these modifications and demonstrates correctness for both UnorderedArrayList and OrderedArrayList

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!