member access within null pointer of type ‘struct ListNode’
You only make sure that runner->next is not null, however after assignment runner = runner->next->next; runner can become null.
You only make sure that runner->next is not null, however after assignment runner = runner->next->next; runner can become null.
See my answer about spatial and temporal locality. In particular, arrays are contiguous memory blocks, so large chunks of them will be loaded into the cache upon first access. This makes it comparatively quick to access future elements of the array. Linked lists on the other hand aren’t necessarily in contiguous blocks of memory, and could … Read more
Vector is another name for dynamic arrays. It is the name used for the dynamic array data structure in C++. If you have experience in Java you may know them with the name ArrayList. (Java also has an old collection class called Vector that is not used nowadays because of problems in how it was … Read more
The problem, as expected, comes in method sort(): A minor problem is just do always execute the bubble sort n*n times. It is actually better check whether there was a change between any pair in the list. If it was, then there is the need to run again all over the list; if not, there … Read more
The problem is that the function list::Subset(list subset) takes its argument by value causing a copy of the list to be made. Since you did not follow the Rule of Three (as noted in Chris’ comment) a shallow copy is made. This means that two instance of list “own” the pointers. When the Subset function … Read more
C implementation of your bonus question, in three lines: