MESSAGE
DATE | 2015-01-22 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] Algoritms
|
From owner-learn-outgoing-at-mrbrklyn.com Thu Jan 22 00:06:50 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id D6A5016112C; Thu, 22 Jan 2015 00:06:50 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id C6155161154; Thu, 22 Jan 2015 00:06:50 -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 0D42516112C for ; Thu, 22 Jan 2015 00:06:49 -0500 (EST) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 90FF016148 for ; Thu, 22 Jan 2015 00:06:48 -0500 (EST) Received: by panix2.panix.com (Postfix, from userid 20529) id 7A23533C79; Thu, 22 Jan 2015 00:06:48 -0500 (EST) Date: Thu, 22 Jan 2015 00:06:48 -0500 From: Ruben Safir To: learn-at-nylxs.com Subject: [LIU Comp Sci] Algoritms Message-ID: <20150122050648.GA3517-at-panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
This HW is stupid.
Last should be 0 and this line fails is position is zero
// Precondition: 0 <= pos <= L.last+1 void InsertAtPosition(List& L, int val, int pos){ if (pos < 0 || pos > ( L.last + 1 )){ exit 0; } /// added by me
for (int i = L.last; i >= pos; i--) { L.a[i+1] = L.a[i]; }
// if array is empty and L.last = -1 this fails resukts in // L.a[0] = L.a[-1]; <<===== Fail
L.a[pos] = val; L.last++; }
Should we just do a rewrite altogether?
|
|