MESSAGE
DATE | 2015-01-23 |
FROM | Kamran
|
SUBJECT | Re: [LIU Comp Sci] study hall today
|
From owner-learn-outgoing-at-mrbrklyn.com Fri Jan 23 11:47:39 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id 9E0EF16117A; Fri, 23 Jan 2015 11:47:39 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 8BD7C16118F; Fri, 23 Jan 2015 11:47:39 -0500 (EST) Delivered-To: learn-at-mrbrklyn.com Received: from mail-qa0-f47.google.com (mail-qa0-f47.google.com [209.85.216.47]) by mrbrklyn.com (Postfix) with ESMTP id C4F7916117A for ; Fri, 23 Jan 2015 11:47:38 -0500 (EST) Received: by mail-qa0-f47.google.com with SMTP id n8so6606793qaq.6 for ; Fri, 23 Jan 2015 08:47:38 -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=+wmfl7ypaP3iJ0K2kDjU/CODO9loqcs0xKmCvhuuNr4=; b=DFTpLhsKSTYzjkI/CPYk4a8mN4vu+qKw7MeMlvi6mcESrVjKE7eqSSfisEijNhqAUj v9CVM/JOLqY8l1393BgBSlAivx/0XBADsQ+RSy8oJJ05XEsCf9mPnj7whMw4aw99SQxv NxzVRA91oIBuB6XIsF6X2mDThauLcqottYSEmj38lhiyUqP7hcLSvIz+3dOXFnWlYS7E hzH4AsZttZ55q30nLDGB4z/8S0pgiDlKS+mdHNuTFFrDQly7F6S0DLiU4yR33Ig4QCW8 qxFK+i8X+tAWiZmq7V4UJ/fZ8JjtxuDfgUTJrM67BdTjKgqBO6PG9D1ilVeefEuA6mR5 dz3g== X-Gm-Message-State: ALoCoQk7qjvZIWgwf4XndUq6j2p+MlFqmgclmIAEugQjXq4LCQhJ4lvPiLXrqeMoukcK8ZMg3Ivr X-Received: by 10.140.102.165 with SMTP id w34mr13700157qge.26.1422031658126; Fri, 23 Jan 2015 08:47:38 -0800 (PST) Received: from [148.4.237.140] (182631b.cst.lightpath.net. [24.38.3.27]) by mx.google.com with ESMTPSA id r2sm1943819qah.1.2015.01.23.08.47.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 08:47:37 -0800 (PST) Message-ID: <54C27B20.2060808-at-my.liu.edu> Date: Fri, 23 Jan 2015 11:47:28 -0500 From: Kamran User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: learn-at-mrbrklyn.com Subject: Re: [LIU Comp Sci] study hall today References: <548EDC03.4030704-at-my.liu.edu> <548EEBDD.3060804-at-my.liu.edu> <548EED54.3060702-at-my.liu.edu> <548EED98.10908-at-my.liu.edu> <5491C69E.2090901-at-my.liu.edu> <5491C805.2040808-at-my.liu.edu> <54C19D2E.5070305-at-panix.com> In-Reply-To: <54C19D2E.5070305-at-panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
Hi Ruben, yes i did. Here is a code of the assignment:
#include #include using namespace std;
struct List { int *a; int n; int last; };
List NewList(int max_size) { List L;
L.a = new int[max_size]; L.n = max_size; L.last = -1;
return L; }
// Precondition: 0 <= pos <= L.last+1 void InsertAtPosition(List& L, int val, int pos) { for (int i = L.last; i >= pos; i--) { L.a[i+1] = L.a[i]; }
L.a[pos] = val; L.last++; }
// Precondition: 0 <= pos <= L.last void DeleteAtPosition(List& L, int pos) { // For you to do
if ((pos > L.last) || (pos < 0)) { cout << endl; cout << "Invalid position number" << endl; return; }
for (int i = pos; i < L.last; i++) { L.a[i] = L.a[i+1]; }
L.last--; }
void InsertFirst(List& L, int val) { InsertAtPosition(L, val, 0); }
void InsertLast(List& L, int val) { // For you to do
InsertAtPosition(L, val, L.last + 1);
}
void DeleteFirst(List& L) { // For you to do
DeleteAtPosition(L, 0);
}
void DeleteLast(List& L) { // For you to do
DeleteAtPosition(L, L.last);
}
bool IsFull(List& L) { return L.last == L.n; }
bool IsEmpty(List& L) { // For you to do return L.last == -1;
}
void PrintList(const List& L) { for (int i = 0; i <= L.last; i++) { cout << L.a[i] << " "; } }
int main() { int val; List L = NewList(100);
while(cout << "Enter value to be inserted (CTL-D to end): ", cin >> val) { if (! IsFull(L)) InsertFirst(L, val); else break; }
cout << endl << endl; PrintList(L); cout << endl;
cin.clear();
// For you to do: Add code to test the functions you wrote.
int pos;
while(cout << "Enter value to be inserted at the end of the list (CTL-D to end): ", cin >> val) { if (! IsFull(L)) { InsertLast(L, val); cout << endl; PrintList(L); cout << endl; } else break; } cout << endl << endl; PrintList(L); cout << endl; cin.clear();
while(cout << "Enter position of value to be deleted (CTL-D to end): ", cin >> pos) { if (! IsEmpty(L)) { if (pos == 0) { DeleteFirst(L); cout << endl; PrintList(L); cout << endl; } else if (pos == L.last) { DeleteLast(L); cout << endl; PrintList(L); cout << endl; } else { DeleteAtPosition(L, pos); cout << endl; PrintList(L); cout << endl; } } else break; } cout << endl; PrintList(L); cin.clear();
return EXIT_SUCCESS; }
On 1/22/2015 8:00 PM, Ruben Safir wrote: > Kamran, do you have any work done yet from that assignment? >
-- Best regards, Kamran Mirzoyev
|
|