package com.javarush.task.pro.task13.task1313;

import java.util.ArrayList;

public class StringsLinkedList {
    private Node first = new Node();
    private Node last = new Node();

    public void printAll() {
        Node currentElement = first.next;
        while ((currentElement) != null) {
            System.out.println(currentElement.value);
            currentElement = currentElement.next;
        }
    }

    public void add(String value) {
       Node node = new Node();
       node.value = value;
       if (first.next == null) {
           first.next = node;
       }
       else {
           last.prev.next = node; // как работает эта строчка кода ?
           node.prev = last.prev;
       }
        last.prev = node;

    }

    public static class Node {
        private Node prev;
        private String value;
        private Node next;
    }
}
last.prev = node - тут понятно. Полю prev объекта last мы присваеваем ссылку на новосозданный объект node. Я ведь правильно понимаю? но на что мы ссылаемся когда пишем last.prev.next ? 🥴