MESSAGE
DATE | 2015-02-27 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] a hate this question
|
From owner-learn-outgoing-at-mrbrklyn.com Fri Feb 27 14:39:47 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id 297251612F0; Fri, 27 Feb 2015 14:39:47 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 1A25F1612E6; Fri, 27 Feb 2015 14:39:46 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id EA5B91612E3; Fri, 27 Feb 2015 14:39:44 -0500 (EST) Received: from [10.0.0.19] (unknown [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 6E976108F3; Fri, 27 Feb 2015 14:39:44 -0500 (EST) Message-ID: <54F0C800.4060200-at-panix.com> Date: Fri, 27 Feb 2015 14:39:44 -0500 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: learn-at-nylxs.com, hangout Subject: [LIU Comp Sci] a hate this question Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
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.
|
|