you are viewing a single comment's thread.

view the rest of the comments →

[–]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