AiSD.Laba1/TestConsoleApp/StackBooksOfList.cs

59 lines
1.4 KiB
C#
Raw Normal View History

2023-02-15 14:40:58 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestConsoleApp
{
internal class StackBooksOfList
{
private NodeBook? firstBook = null;
/// <summary>
/// Возвращает элемент из стека
/// </summary>
/// <returns>Экземпляр книги</returns>
public static Book? pop()
{
if (firstBook == null)
{
return null;
}
else
{
NodeBook temp = firstBook;
firstBook = firstBook.nextNodeBook;
return temp.book;
}
}
/// <summary>
/// Добавление значения в стек
/// </summary>
/// <param name="newBook">Объект новой книги</param>
public void push(Book newBook)
{
//Создание узла с книгой
NodeBook newNode = new NodeBook();
newNode.book = newBook;
newNode.nextNodeBook = firstBook;
firstBook = newNode;
}
public void printAll()
{
NodeBook temp = firstBook;
while (temp != null)
{
Console.WriteLine(temp.book.name);
temp = temp.nextNodeBook;
}
}
}
}