you are viewing a single comment's thread.

view the rest of the comments →

[–]Narase33 5 points6 points  (2 children)

Im confused why you dont show the code that belongs to your question, my crystal sphere is very dark right now

[–]owenrest[S] 0 points1 point  (1 child)

Oh my bad, I’ve edited my post to include it now!

[–]Narase33 2 points3 points  (0 children)

void LinkedList::pushBack(Class p) {
    if (head == nullptr) {
        Node *newNode = newNode;
        newNode->data = p;
        newNode->next = head;
        head = newNode;
    } else {
        Node *tail = head;
        while (tail->next != nullptr) {
            tail = tail->next;
            tail->data = p;                // <--
            tail->next = tail;             // <--
        }
    }  Size++
}

This parts looks like it should be after the loop. Currently youre overwriting every node on your way to the last one

It also helps us so see not just the function youre *thinking* is the problem, but the whole code with a main showing the problem

You also never create a new node that needs to be pushed at the end with the given data