Recommendations on improving my built-in linked list garbage collection : <p>I'm currently learning about linked lists, and I'm building one myself in C++ in order to fully grasp the concept. Every method seems to work. However, I'm not confident in my implemented garbage collection of my Node class and LinkedList class. Can anyone look at it and give any suggestions for improval? Thank you!</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;map&gt;

template&lt;class T&gt;
struct Node
{
    T value;
    Node* next;

    Node() {
        next = nullptr; // Set the default of next to nullptr
    }
    ~Node() {
        if (next) {
            delete next;
            next = nullptr;
        }
    }
};

template&lt;class T&gt;
class LinkedList
{
private:
    Node&lt;T&gt;* head;
    Node&lt;T&gt;* tail;
    unsigned int length;

    Node&lt;T&gt;* traverseToIndex(const unsigned short&amp; index);
public:
    LinkedList();
    ~LinkedList();
    void append(const T&amp; value);
    void prepend(const T&amp; value);
    void insert(const unsigned short&amp; index, const T&amp; value);
    void remove(const unsigned short&amp; index);
};

int main()
{
    LinkedList&lt;int&gt; nums;
    nums.append(5);
    nums.append(1);
    nums.append(3);
    nums.append(4);
    nums.remove(2);

    return 0;
}

template&lt;class T&gt;
LinkedList&lt;T&gt;::LinkedList()
{
    this-&gt;length = 0;
    head = new Node&lt;T&gt;;
    tail = head;
}

template&lt;class T&gt;
LinkedList&lt;T&gt;::~LinkedList()
{
    delete head;
}

template&lt;class T&gt;
Node&lt;T&gt;* LinkedList&lt;T&gt;::traverseToIndex(const unsigned short&amp; index)
{
    if (index &gt;= this-&gt;length) return tail;

    Node&lt;T&gt;* currentNode = head;
    for (unsigned short i = 0; i &lt; index; i++) {
        currentNode = currentNode-&gt;next;
    }
    return currentNode;
}

template&lt;class T&gt;
void LinkedList&lt;T&gt;::append(const T&amp; value)
{
    if (length == 0) {
        head-&gt;value = value;
    } else {
        Node&lt;T&gt;* newNode = new Node&lt;T&gt;;
        newNode-&gt;value = value;
        tail-&gt;next = newNode;
        tail = newNode;
    }
    length++;
}

template&lt;class T&gt;
void LinkedList&lt;T&gt;::prepend(const T&amp; value)
{
    Node&lt;T&gt;* newNode = new Node&lt;T&gt;;
    newNode-&gt;value = value;
    newNode-&gt;next = head;
    head = newNode;
}

template&lt;class T&gt;
void LinkedList&lt;T&gt;::insert(const unsigned short&amp; index, const T&amp; value)
{
    if (index &gt;= this-&gt;length || index &lt;= 0) return;

    Node&lt;T&gt;* before = this-&gt;traverseToIndex(index - 1);
    Node&lt;T&gt;* after = before-&gt;next;

    Node&lt;T&gt;* newNode = new Node&lt;T&gt;;
    newNode-&gt;value = value;
    newNode-&gt;next = after;

    before-&gt;next = newNode;

    this-&gt;length++;
}

template&lt;class T&gt;
void LinkedList&lt;T&gt;::remove(const unsigned short&amp; index)
{
    Node&lt;T&gt;* before = this-&gt;traverseToIndex(index - 1);
    Node&lt;T&gt;* deletedNode = before-&gt;next;
    Node&lt;T&gt;* after = deletedNode-&gt;next;
    before-&gt;next = after;

    this-&gt;length--;
}
</code></pre>
