I'm trying to append an array of characters to a doubly linked list and this is what I have so far. I'm confused about how to get my list to display correctly when I call display_list() in main() since nothing prints. I know I must not be appending correctly, I'm just having a hard time wrapping my head around what to do.
understand the purpose of your functions
get_node() creates a node, so doing newNode = new Node; in append() is wrong, it is not its responsibility and causes a memory leak
now, you check if(!head) but then never change head
head always remains null, so your list is empty
¿where append() should add the new item? ¿at the start? ¿at the end? ¿somewhere in the middle?
That makes sense.
In the case of this program I want to keep appending to the end of the list.
I adjusted the append function to this...
1 2 3 4 5 6 7
//Append function to add new number to the linked list.
void append(char entry) {
if (!head) {
head = get_node(entry, nullptr, nullptr);
}
head->next = get_node(entry, nullptr, head->back);
}