Question: PLEASE ADD MEANINGFUL COMMENT TO ALL THE CODE!! I WILL BE SURE TO UPVOTE!!! (the code is in c#) namespace hello { internal class Program

PLEASE ADD MEANINGFUL COMMENT TO ALL THE CODE!! I WILL BE SURE TO UPVOTE!!! (the code is in c#)

namespace hello { internal class Program { static void Main(string[] args) { Console.WriteLine("blah blah"); } } internal class RayList : IEnumerable where T : IComparable { private T[] array; public int count { get; private set; } public int capacity { get { return array.Length; } } public bool IsFull() { //Simplified version only return (count == capacity); } public bool IsEmpty() { return (count == 0); } public void PrintArray() { for (int i = 0; i < count; i++) { Console.Write($"{array[i]}, "); } Console.WriteLine(); }

public void AddLast(T newValue) //O(n) worst case, O(1) on average { if (IsFull()) { DoubleTheCapacity(); } array[count] = newValue; count++;

} public void AddFirst(T newValue) { Insert(0, newValue); } public void Add(T newvalue) { AddLast(newvalue); } public void DeleteValue(T DeletedValue) {

T[] tempArray = new T[capacity]; int i = 0; bool found = false; for (int j = 0; j < count; j++) { if (array[j].CompareTo(DeletedValue) == 0 & !found) { found = true; continue; } //copy the current value to the temp array and iterate i tempArray[i] = array[j]; i++; } array = tempArray; if (found) { count--; } } public void Delete(int index) { if (index < 0 || index > count) throw new IndexOutOfRangeException(); T[] tempArray = new T[capacity]; for (int i = 0; i < index; i++) { tempArray[i] = array[i]; } for (int i = index; i < count; i++) { tempArray[i] = array[i + 1]; } array = tempArray; count--; } public void DeleteFirst() { Delete(0); } public void DeleteLast() { Delete(count - 1); } public void DoubleTheCapacity() { T[] newArray = new T[capacity * 2]; for (int i = 0; i < count; i++) { newArray[i] = array[i];

} array = newArray; } public void Insert(int index, T newValue) { if (index < 0 || index > count) throw new IndexOutOfRangeException(); if (IsFull()) { DoubleTheCapacity(); } for (int i = index; i >= 1; i--) { array[i] = array[i - 1]; } array[0] = newValue; //Add on to the array count++; } public void Clear() //O(1) { count = 0; }

public void Reverse() { T[] tempArray = new T[capacity]; for (int i = 0; i < count; i++) { tempArray[i] = array[count - 1 - i]; } array = tempArray; }

public static RayList operator +(RayList firstlist, RayList secondList) { RayList newlist = new RayList(firstlist.capacity + secondList.capacity); foreach (var val in firstlist.array) newlist.Add(val); foreach (var val in secondList.array) newlist.Add(val); return newlist; }

public IEnumerator GetEnumerator() { for (int i = 0; i < count; i++) { yield return array[i]; } } IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }

public T this[int i] { get { if (i < 0 || i > count) throw new IndexOutOfRangeException(); return array[i]; } set { array[i] = value; } } public RayList(int initialCapacity = 1) { array = new T[initialCapacity]; } public RayList(RayList oldList) { count = oldList.count; array = new T[oldList.capacity]; for (int i = 0; i < count; i++) { array[i] = oldList[i]; } } } }

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!