Timeline for Deficient Numbers
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 10, 2018 at 16:16 | vote | accept | rudicangiotti | ||
Sep 15, 2018 at 15:08 | comment | added | rudicangiotti | In other words, since each node includes a value and a pointer to next node, it would be better and easier to swap actual values instead the linkages between nodes, is it right? | |
Sep 15, 2018 at 1:04 | comment | added | Deduplicator | @rudicangiotti I mean that the identity of the individual nodes is not actually relevant, only their position in the list and their payload. And in this case it is easier to swap the payload than swap node-positions. | |
Sep 14, 2018 at 23:13 | comment | added | rudicangiotti |
Thank you again, @Deduplicator. Anyway, I have another question, this time related to point 11: what do you mean by saying that thelistSort() function doesn't really have to re-order the nodes to sort the values?
|
|
Sep 14, 2018 at 9:56 | comment | added | Deduplicator |
@rudicangiotti Yes to both. You can certainly write code with the assumption that allocation-failure is a fatal error. Doing so has the virtue of simplifying error-handling considerably. Signalling the error to the caller, in C mostly with the return-value, though errno is also used (mostly for supplementary Information), as well as out-parameters or rarely longjmp() , is preferred, especially in library-code.
|
|
Sep 13, 2018 at 23:05 | comment | added | rudicangiotti |
Referring, instead, to the same paragraph, point 7, could this be a valid solution to manage memory allocation errors? List* list = malloc(sizeof list); if (list == NULL) return NULL; Or even, is it better to use something like the exit(EXIT_FAILURE) function?
|
|
Sep 9, 2018 at 20:06 | comment | added | Deduplicator | It certainly avoids errors due to manually calculating for the wrong platform. The other point was stronger coupling between space wanted and space requested than magic number respective sizeof(TYPE) provides. | |
Sep 9, 2018 at 12:22 | comment | added | rudicangiotti | Okay, thanks. Anyway, using the pointer to the memory allocated just improves the code readability, or can also avoid errors (for instance, when the code is compiled on another OS)? | |
Sep 8, 2018 at 23:30 | comment | added | Deduplicator | No, rather malloc(sizeof *pointer). | |
Sep 8, 2018 at 12:17 | comment | added | rudicangiotti |
Referring to the Your Code paragraph, point 8, do you mean that it is better a statement like malloc(2 * 4) instead of malloc(sizeof(ListNode)) , considering that a ListNode will contain an int value (then, 4 bytes) and a pointer to the next node, which is another int value?
|
|
Sep 5, 2018 at 17:26 | history | edited | Deduplicator | CC BY-SA 4.0 |
added 312 characters in body
|
Sep 5, 2018 at 17:12 | history | answered | Deduplicator | CC BY-SA 4.0 |