/
Ersh
/
homeworkAlgo4
Обзор
Документация
Войти
/
Ersh
/
homeworkAlgo4
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/LinkedStack.java
52 строки
1 KB
Ersh
upload files
28 ноя 2025, 17:17
28 ноя 2025, 17:17
d33fc3f
Код
Авторство
О чём код?
public class LinkedStack { private Node tail; private int size; public void push(int value) { Node node = new Node(value); if (tail != null) { node.setPrev(tail); } tail = node; size++; } public int pop() { if (tail == null) { throw new RuntimeException("Stack is empty"); } int value = tail.getValue(); tail = tail.getPrev(); size--; return value; } public int getSize() { return size; } public boolean isEmpty() { return tail == null; } public String toString() { if (tail == null) { return "EMPTY"; } StringBuilder sb = new StringBuilder(); Node current = tail; boolean first = true; while (current != null) { if (!first) { sb.append(" -> "); } sb.append(current.getValue()); current = current.getPrev(); first = false; } return sb.toString(); } }