// Insert a student into the proper location in the array public void Insert(student s) { if (size == 0) { array[0] = s; size++; return; } int index = 0; while (index < size && s.TNumber > array[index].TNumber) index++; for (int i = size; i > index; i--) array[i] = array[i - 1]; array[index] = s; size++; }
static void Main(string[] args) { sortedArray arr = new sortedArray(500); Console.Write("How many students will you enter? "); int numStudents = int.Parse(Console.ReadLine()); for (int counter = 0; counter < numStudents; counter++) { student tmpStudent = new student(0, "", ""); Console.WriteLine("Information for student: {0}", counter + 1); Console.Write("TNumber = "); tmpStudent.TNumber = int.Parse(Console.ReadLine()); Console.Write("Name = "); tmpStudent.Name = Console.ReadLine(); Console.Write("Advisor = "); tmpStudent.Advisor = Console.ReadLine(); Console.WriteLine(); arr.Insert(tmpStudent); } Console.WriteLine("Display all students"); arr.Display(); Console.WriteLine("\nFind the student with maximum TNumber"); student studentTemp = arr.Max(); Console.WriteLine("TNumber: {0} Name: {1} Advisor: {2}", studentTemp.TNumber, studentTemp.Name, studentTemp.Advisor); Console.WriteLine("\nFind the student with minimum TNumber"); studentTemp = arr.Min(); Console.WriteLine("TNumber: {0} Name: {1} Advisor: {2}", studentTemp.TNumber, studentTemp.Name, studentTemp.Advisor); Console.Write("\nEnter TNumber to search for a student: "); int t = int.Parse(Console.ReadLine()); Console.WriteLine("Student located at index: " + arr.BinarySearch(t)); Console.Write("\nEnter TNumber to delete a student: "); t = int.Parse(Console.ReadLine()); Console.WriteLine("\nDelete students with TNumber {0}", t); arr.Delete(t); arr.Display(); Console.ReadLine(); }