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
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
public IEnumerator
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
