AiSD.Laba1/Stack/StackBooksOfList.cs
2023-02-16 15:59:01 +04:00

59 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stack
{
internal class StackBooksOfList
{
private NodeBook? firstBook = null;
/// <summary>
/// Возвращает элемент из стека
/// </summary>
/// <returns>Экземпляр книги</returns>
public 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;
}
}
}
}