Skip to main content
9 events
when toggle format what by license comment
Jun 10, 2020 at 13:24 history edited CommunityBot
Commonmark migration
Dec 1, 2017 at 3:09 comment added chux An applications may have millions of linked-lists with the majority of them empty - LL are a core building block for many applications. Having an efficient empty size of 4 vs. 8 is significant. Concerning bug-ness this answer's first header & LL approach failed to free memory properly and did not check for out-of-memory in the LL allocation path. Various approaches have their value.
Dec 1, 2017 at 3:06 history edited user1118321 CC BY-SA 3.0
Fixed some stuff I forgot thanks to chux comment.
Dec 1, 2017 at 3:02 comment added user1118321 Regarding only keeping a pointer to tail - that seems like the type of thing that will lead to subtle bugs because it's non-obvious, and it only saves 4-8 bytes typically, so not worth it in my opinion. The struct with both head and tail is much clearer. But good points otherwise. I'll make an update shortly.
Nov 30, 2017 at 21:34 comment added chux This code checks for allocation error with if (result == NULL), that is good. Yet does not look for allocation error due to append(result, value % 10);, that is inconsistent. OP's use of root allows for a single check (presently missing) right after the malloc() an advantage to OP's header-less LL.
Nov 30, 2017 at 21:22 comment added chux void free_list(IntList *list) should set its members to NULL before returning. list->head = NULL; (and list->tail = NULL; if implemented.) Otherwise, free(list) may be needed here.
Nov 30, 2017 at 21:13 comment added chux A 2 member struct like typedef struct IntList { IntNode *head; IntNode *tail; } IntList; is not necessary to add to the head and tail of a LL. A pointer to the tail (whose next member points to the head) is sufficient.
Nov 28, 2017 at 13:45 vote accept cm007
Nov 28, 2017 at 5:53 history answered user1118321 CC BY-SA 3.0