Implementing a linked list, some problems
Ok, I am implementing a basic linked list, in the form of a stack, and for my push function I have:
Code:
void Push(Node** head, int data)
{
Node* new_node = new Node;
new_node->data = data;
new_node->next = *head;
*head = new_node;
}
now, this works fine, displaying its data works perfectly. However, it is very.... un-modular to future development. When I try to do this:
Code:
void Push(Node** head, Node* new_node)
{
new_node->next = *head;
*head = new_node;
};
displaying it using the standard while(Current->next != NULL) loop, it goes into an infinite loop, only displaying the last pushed number.
I was wondering what I am doing wrong, cause linked lists are pretty basic things, and I had them working perfectly before, but during this semester of college, my main focus was making sure I got a 4.0 GPA and so I forgot the proper way to do linked lists.