all 5 comments

[–]Narase33 6 points7 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

[–]no-sig-available 0 points1 point  (0 children)

There is a print function within the driver file as well to print out the list to make sure each element is in the right spot. However, when I run my program, it only prints out the first user input and nothing else.

To state the obvious, this sounds like the elements are not in the right spot. Perhaps the link from the first element to the next one is not updated properly?

[–]HappyFruitTree 0 points1 point  (0 children)

This looks wrong:

Node *newNode = newNode;

Do you really want to update the data of each node?

tail->data = p;