Что является «головой» связанного списка?

Я работаю со связанными списками в Java, поэтому я пытаюсь понять концепцию единого связанного списка.

head -> 12 -> 34 -> 56 -> null

head.next будет 12 (то же самое, что и node1). Однако что же тогда такое голова?

Обновление: В чем разница между ссылкой и указателем?

Обновление2: Итак, если голова будет 12 ] и head.next равно 34 , то не Означает ли, что эта следующая функция пропускает первый узел, чтобы увидеть, является ли он пустым?

public void add(Object data, int index)
    // post: inserts the specified element at the specified position in this list.
    {
        Node temp = new Node(data);
        Node current = head;
        // crawl to the requested index or the last element in the list,
        // whichever comes first
        for(int i = 1; i < index && current.getNext() != null; i++)
        {
            current = current.getNext();
        }
        // set the new node's next-node reference to this node's next-node reference
        temp.setNext(current.getNext());
        // now set this node's next-node reference to the new node
        current.setNext(temp);
        listCount++;// increment the number of elements variable
    }

Источник: http://www.mycstutorials.com/articles/data_structures/linkedlists

14
задан TheExorcist 27 March 2018 в 12:26
поделиться