MESSAGE
DATE | 2015-02-28 |
FROM | Ruben
|
SUBJECT | Subject: [LIU Comp Sci] Linked List Test Question
|
From owner-learn-outgoing-at-mrbrklyn.com Sat Feb 28 23:54:05 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id E4E861612FE; Sat, 28 Feb 2015 23:54:04 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id C23F1161301; Sat, 28 Feb 2015 23:54:04 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mail-qg0-f51.google.com (mail-qg0-f51.google.com [209.85.192.51]) by mrbrklyn.com (Postfix) with ESMTP id 66C0D1612FE for ; Sat, 28 Feb 2015 23:53:59 -0500 (EST) Received: by mail-qg0-f51.google.com with SMTP id e89so6317445qgf.10 for ; Sat, 28 Feb 2015 20:53:58 -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:content-type:content-transfer-encoding; bh=DmQWtFUkMMlG8taZ6BOhMoU7uNgD+LM+Fs+yFdpi/X8=; b=jWnpFleA7x7jr1TWev/MeOM1UnHkH18+TOgePz/rNxBKF0aUXy5CBTjOS3P4wTKVdA HesrS/CW5ynC8h2V25wtU54Yf/ce86RqVJ8SIY37igHhtRuTW64AkR4DOI7bPkbrkhm1 hu+aX+SyC+RGzNm9lzsWqc+6N46duDIzy6uN1jZLDX6Nyou87FHjzRia28NoBc77ZIA2 cq3+S2XIA2vmhqTxi9dEqGyCbU2CCla9ekGvxEZb9qprl8xn5NYlLobOFYtmDJLukKt8 YJFjBl8ibZcJwAgAeS26z3l2Cv+ZFPY22cBXthhJ6eaJcuHd8p5pVYHsYKfJycPMDlNF OLWg== X-Gm-Message-State: ALoCoQn4i6eC2SmG8JDuv899/DPd7vKzSlYcIYDWQ1HbGP2LRiePQ5sHUup/l9/c/7IteAVXXyJP X-Received: by 10.140.234.17 with SMTP id f17mr43190201qhc.64.1425185637469; Sat, 28 Feb 2015 20:53:57 -0800 (PST) Received: from [10.0.0.19] ([96.57.23.82]) by mx.google.com with ESMTPSA id r6sm5877202qah.43.2015.02.28.20.53.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Feb 2015 20:53:57 -0800 (PST) Message-ID: <54F29B64.2030802-at-my.liu.edu> Date: Sat, 28 Feb 2015 23:53:56 -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: jose.rodriguez-at-liu.edu Subject: [LIU Comp Sci] Linked List Test Question X-Priority: 2 (High) 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
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;
|
|