MESSAGE
DATE | 2015-03-01 |
FROM | Ruben
|
SUBJECT | Subject: [LIU Comp Sci] Fwd: Re: Linked List Test Question
|
From owner-learn-outgoing-at-mrbrklyn.com Sun Mar 1 12:56:37 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id 872501612F7; Sun, 1 Mar 2015 12:56:37 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 7A5F7161300; Sun, 1 Mar 2015 12:56:37 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mail-qa0-f47.google.com (mail-qa0-f47.google.com [209.85.216.47]) by mrbrklyn.com (Postfix) with ESMTP id C1CD81612F7 for ; Sun, 1 Mar 2015 12:56:36 -0500 (EST) Received: by mail-qa0-f47.google.com with SMTP id v10so19848234qac.6 for ; Sun, 01 Mar 2015 09:56:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=VUG3Sv0EnDAnMAZsiJm7qdcAH2XXumnyQFzDv7L8rJg=; b=Z1RNn+0cRtbViq+f0BuYqi0x3ZQpJN4V8PbkZLugKDiFFE1k5j1caJH9GrgE4mpkdZ ehUfXYT75r+e2Fqm43IJp/52Z3xGuuxiJQz3jTicVvBX64U0tHcgCjPkwi3AD0bWTfO4 DO+bouxhf9q0RvpuHh1CpKQTBFhiG6s0HSEnUN7rZfJsvjJqObfZz0JkINIXXzXalpOn LflB9n+JeBFxa+S6bydKKcIsWydj8mD1Jgdc68iDoHWCoOJEZwTYruPwd1ganLjaDIsn Xz9DR5ARUEngDqLCeumwe5KtENWwJWlqhA85sYUOS8bjo2A+f7gVTHJvdBO7fGfzj4Ef vUgA== X-Gm-Message-State: ALoCoQkUEEYbBvMhgAVY6hSmkWh2iiB8SUCkrf5pKbxN4g/2duVorAhyaQvvxKNXQ2PdoHQ+qz3V X-Received: by 10.140.216.139 with SMTP id m133mr35981064qhb.6.1425232595387; Sun, 01 Mar 2015 09:56:35 -0800 (PST) Received: from [10.0.0.19] ([96.57.23.82]) by mx.google.com with ESMTPSA id r13sm6845386qan.7.2015.03.01.09.56.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Mar 2015 09:56:35 -0800 (PST) Message-ID: <54F352D2.60702-at-my.liu.edu> Date: Sun, 01 Mar 2015 12:56:34 -0500 From: Ruben 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 Subject: [LIU Comp Sci] Fwd: Re: Linked List Test Question References: <781503C8-CEB4-4856-A980-10A1C75C54E4-at-liu.edu> In-Reply-To: <781503C8-CEB4-4856-A980-10A1C75C54E4-at-liu.edu> X-Forwarded-Message-Id: <781503C8-CEB4-4856-A980-10A1C75C54E4-at-liu.edu> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
-------- Forwarded Message -------- Subject: Re: Linked List Test Question Date: Sun, 1 Mar 2015 12:18:10 +0000 From: Jose A. Rodriguez To: Ruben
The question does not refer to any algorithm in particular. It just refers to the situation depicted. Pointer variable q is currently pointing to node containing 20. Pointer variable r is currently pointing to node containing 30. Pointer variable n is pointing to the new node to be inserted. So
q -> next = n; n->next = r;
is perfectly fine. So would be
n -> next = r; q-> next = n;
if that had been a choice.
How I got q and r to point to 20 and 30 is not relevant to the question.
> On Feb 28, 2015, at 11:54 PM, "Ruben" wrote: > > > I'm looking at this question and I don't think it is right. In > theory it is correct but in reality with the algorithm, you can't > detach the upper part of the linked list and just assign it > because it then ends up as lost pointer and leaked memory. > > > > That is why you always assign the value of q->next to your new > node FIRST. Now you have a handle on the upper part of the list > and you can now assign q->next with your new node address and your > finished. > > > > > Question 5 > > 5 out of 10 points > > > > Partial Credit > > Consider the linked list in the handout. Which of the following > correctly inserts node containing 25 between the nodes containing 20 and 30? > > > > Correctd. > > n->next = q->next; > > q->next = n; > > Answers: > Correcta. > > q->next = n; > > n->next = r; > > > > b. > > p->next = n; > > n->next = r; > > > > c. > > q->next = n; > > n->next = q->next; > > > > Correctd. > > n->next = q->next; > > q->next = n; >
|
|