MESSAGE
DATE | 2015-02-27 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] a hate this question
|
This is an example why Rodriquez coding drives me crazy. Fuck the question, I hate this code. With all do respect that he is a brilliant instructor and a genius, the code is Bullshit and one should never write code like this because it exposes other coders to dangerous practices.
By pushing curr to NULL in the loop, instead of just testing for curr->next == NULL what you do is take the chance that someone with then __use__ curr->next when curr-> is past the alloted memory in the heap, which is the state you leave it in when you finish the loop. In other words, this is not defensive coding. I LEARNED to code defensively and this code would have gotten me a ZERO when I went to school.
When I see this, I can't answer the question because all I can see is the future train wreck..
~~~~~~~~~~~~~~~~~
The following for-loop locates the first occurrence of 20 in a linked list *having a dummy node:*
Assume *node *head *points to the dummy node.
node *prev, *curr;
for (prev = head, curr = head->next; curr != 0; prev = curr, curr = curr->next) {
if (curr->data == 20) break;
}
If 20 does not occur in the list, what does *prev *point to after the loop ends?
a.
The node preceeding the last node in the list.
b.
Undefined.
c.
The dummy node.
d.
The last node in the list.
|
|