public void Push(Person m) { if (_counter < N) { _counter++; arrayList[_counter] = m; } else Console.WriteLine("Stack Overflow"); }
public void Sort() { Person[] array = new Person[100]; for (int i = 0; i < 100; i++) array[i] = new Person(); for (int i = 0; i <= _counter; i++) { array[arrayList[i]._age]._age = array[arrayList[i]._age]._age + 1; array[arrayList[i]._age]._name = array[arrayList[i]._age]._name + arrayList[i]._name + " "; } int b = 0; for (int j = 0; j < 100; j++) for (int i = 0; i < array[j]._age; i++) { arrayList[b]._age = j; if (array[j]._age != 1) { arrayList[b]._name = null; for (int k = 0; k <= array[j]._name.IndexOf(' '); k++) arrayList[b]._name = arrayList[b]._name + array[j]._name[k]; array[j]._name = array[j]._name.Remove(0, array[j]._name.IndexOf(' ') + 1); } else arrayList[b]._name = array[j]._name; b++; } }
static void Main(string[] args) { List myArray = new List(); Person person1 = new Person("Andrew", 57); Person person4 = new Person("Bob", 31); Person person2 = new Person("Kate", 16); Person person3 = new Person("Jolly", 28); Person person5 = new Person("Kevin", 35); myArray.Push(person1); myArray.Push(person2); myArray.Push(person3); myArray.Push(person4); myArray.Push(person5); Console.WriteLine("Your list of people: "); myArray.Print(); Console.WriteLine("\nSorted list: "); myArray.Sort(); myArray.Print(); Console.ReadKey(); }