Docsity

A Circularly Linked Singly Linked Array List ADT | CSC 1254, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Circular ArrayList ADT CSc 1254: Programming Project # 3
A Circularly-Linked Singly-linked Array List
ADT
Out: 10/23
Due: 11/10 by 11:59 PM
Learning Objectives
•Develop a Circular-linked singly-linked ADT.
•Understand the avoidance of memory leaks.
•Understand the use and implementation of destructors.
•Understand the use and implementation of copy constructors.
Arrays are a rather primitive construct with limited functionality. An array
list provide greater functionality. Like an array, it is a collection of homoge-
neous data but it, additionally, offers two significant conveniences:
•Array list can grow and shrink as needed.
•The ArrayList class supplies methods for many common tasks, such as
inserting and removing elements.
In Lecture # 15, we introduced a strategy for implementing a parameterized
stack ADT that uses one external pointer (head) and a singly-linked list.
Your task in this project is to implement a parameterized ArrayList ADT
using a singly-linked, circularly linked list similar to the stack implementation
we discussed in that lecture. There is only one external pointer which points
to the rear of the array list and the node at the rear has a pointer to the
node at the front of the array list. The rear pointer is used in inserting
and deleting items. Be very careful when de-allocating memory to avoid
memory leaks. Do not leave inaccessible memory or dangling pointers. Free
up memory that is not being used. By now you should have enough practice
with pointer assignments. This project will test your ability to correctly
move pointers around.
Duncan 1 Fall 2009
pf3
pf4
pf5

Partial preview of the text

Download A Circularly Linked Singly Linked Array List ADT | CSC 1254 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

A Circularly-Linked Singly-linked Array List

ADT

Out: 10/ Due: 11/10 by 11:59 PM

Learning Objectives

  • Develop a Circular-linked singly-linked ADT.
  • Understand the avoidance of memory leaks.
  • Understand the use and implementation of destructors.
  • Understand the use and implementation of copy constructors.

Arrays are a rather primitive construct with limited functionality. An array list provide greater functionality. Like an array, it is a collection of homoge- neous data but it, additionally, offers two significant conveniences:

  • Array list can grow and shrink as needed.
  • The ArrayList class supplies methods for many common tasks, such as inserting and removing elements.

In Lecture # 15, we introduced a strategy for implementing a parameterized stack ADT that uses one external pointer (head ) and a singly-linked list. Your task in this project is to implement a parameterized ArrayList ADT using a singly-linked, circularly linked list similar to the stack implementation we discussed in that lecture. There is only one external pointer which points to the rear of the array list and the node at the rear has a pointer to the node at the front of the array list. The rear pointer is used in inserting and deleting items. Be very careful when de-allocating memory to avoid memory leaks. Do not leave inaccessible memory or dangling pointers. Free up memory that is not being used. By now you should have enough practice with pointer assignments. This project will test your ability to correctly move pointers around.

Here are basic outline of the parameterized classes that you will need.

... class ArrayListException {

class ArrayList { // member functions ... // implement the destructor as a virtual function; ... private:

. ... Node* rear; long length; };

class Node { public: //constructor ... private: T data; Node* next; ... friend class ArrayList..; };

  1. Appends an element to the end of this array list.

void add(T element);

  1. inserts an element into the array list at the specified position and throws an ArrayList exception if index < 0 or index > size of the array list.

void add(int index, T element) throw (ArrayListException);

  1. accesses the element at the specified position and throws an exception if index < 0 or index > size-1 of the array list.

T& operator[](int index) throw (ArrayListException);

  1. This function removes the returns the element at the specified position in the array list or throws an exception if index < 0 or index > size- of the array list.

T remove(int index) throw (ArrayListException);

  1. The number of elements in the array list.

long size() const;

Copy the following files from the class directory: arraylist.cpp, arraylist.h and arraylisttest.cpp. Name your executable file arraylisttest. I have also included arraylisttestexe a working binary version of the code. You may copy this file and run it to have a feel for how I expect your code to work when you are done. You will create your own interface file (arraylist.h), containing the ArrayList class with an inner Node class and an ArrayListException class definitions, and implementation file (arraylist.cpp), containing the member functions of the Node and ArrayList classes. This is going to be more or less along the same lines as the parameterized stack implementation provided in lecture # 15 except that the ArrayList class will be circularly-linked.

Compile your program with your makefile until it works properly. Once you are satisfied that your program properly compiles and it is free of any syntax and/or semantic errors, submit your work. You may submit your work as many times as you wish once the due time has not elapsed. After the due time, any further submission will mean that you get no points for the lab.

Submitting Your Work

  1. Type make clean at the system prompt to remove any object, core and executable file.
  2. All source code files you submit must have a header with the following:

@file filename @author your name @date 9999-99- Description: describe what this file does Course: CS1254. Logon ID: cs1254xx Project #: 3 Instructor: Duncan */

  1. Submit your assignment to the grader with the following command: ∼cs1254 dun/bin/p copy 3 This command copies everything in your prog3 directory.
  2. Once p copy is finished, check to see if all required files have been submitted: ∼cs1254 dun/bin/verify 3