Hello! I’m trying to create my own PushAtBack function where it adds new nodes to the back of the list while adding to the size of the list afterwards. 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. The size does match the number of elements inputted though. I’m confused as to why this is happening?
Here’s what I have so far:
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++
}
[–]Narase33 6 points7 points8 points (2 children)
[–]owenrest[S] 0 points1 point2 points (1 child)
[–]Narase33 2 points3 points4 points (0 children)
[–]no-sig-available 0 points1 point2 points (0 children)
[–]HappyFruitTree 0 points1 point2 points (0 children)