static void Main(string[] args) { CustomList myList = new CustomList(); myList.Add(45); myList.Add(25); myList.Add(15); myList.Add(35); Console.WriteLine(myList.RemoveAt(2)); myList.InsertAt(1, 40); myList.InsertAt(3, 30); Console.WriteLine(myList.Contains(30)); Console.WriteLine(myList.Contains(120)); myList.Swap(0, 3); CustomStack myStack = new CustomStack(); myStack.Push(5); myStack.Push(4); myStack.Push(3); Console.WriteLine(myStack.Peek()); Console.WriteLine(myStack.Pop()); }
public static CustomList <T> operator +(CustomList <T> list1, CustomList <T> list2) { T[] temporary = new T[list1.Capacity + list2.Capacity]; CustomList <T> newList = new CustomList <T>(); newList.contents = temporary; for (int i = 0; i < list1.Count; i++) { newList.InsertAt(i, list1[i]); } for (int i = list1.Count; i < list1.count + list2.Count; i++) { newList.InsertAt(i, list2[i - list1.Count]); } return(newList); }
public static CustomList <T> operator -(CustomList <T> list1, CustomList <T> list2) { T[] temporary = new T[list1.Capacity]; CustomList <T> newList = new CustomList <T>(); newList.contents = temporary; for (int i = 0; i < list1.Count; i++) { newList.InsertAt(i, list1[i]); } for (int i = 0; i < newList.Count; i++) { if (newList[i].Equals(list2[i])) { newList.RemoveAt(i); } } return(newList); }