Created
May 27, 2021 12:55
-
-
Save di-ma-73/1f579cb294b1bd47c487fe94717dc0e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Push(string N, string BD, double Avg) | |
{ | |
Item temp = head; | |
Item temp1 = new Item(); // Это "каркас" для ячейки списка, куда положим элемент, который будем добавлять. | |
temp1.value = new Student(); // Теперь создадим "каркас" для самого объекта-студента, куда запишем его данные. | |
Console.WriteLine("\nВведите имя студента: "); | |
temp1.value.Name = Convert.ToString(Console.ReadLine()); // Convert.ToString() лучше убрать. | |
Console.WriteLine("\nВведите сред. ариф. студента: "); | |
temp1.value.BirthDate = Convert.ToString(Console.ReadLine()); | |
// Здесь тоже, и переменная называется BirthDate, а вводится не дата рождения. | |
Console.WriteLine("\nВведите сред. ариф. студента: "); | |
temp1.value.AvgPoint = Convert.ToDouble(Console.ReadLine()); | |
// При добавлении элемента нужно проверить, а есть ли у нас уже список (т.е. head/temp указывает на что-то кроме null?). | |
if (temp == null) // Если добавляется первый элемент, а у нас ещё пока нет списка | |
{ | |
// ... | |
} | |
else | |
{ | |
// ... | |
} | |
// temp1 это наш созданный новый объект, он не связан ни с чем. Здесь должен быть temp, чтобы уйти в конец | |
while (temp.next != null) | |
{ | |
temp = temp.next; | |
} | |
temp.next = temp1; // не `temp1.next = temp`, а наоборот. | |
Console.WriteLine(); | |
// Ниже должен быть temp1, а не temp, потому что новый объект в temp1. Либо сделать `temp = temp.next` | |
Console.WriteLine("\nНовый элемент успешно добавлен " + "[" + temp1.value.Name + " " + temp1.value.BirthDate + | |
" " + temp1.value.AvgPoint + "]"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment