You are on page 1of 2

Lab 1

We dene a list to be a nite, ordered sequence of data items known as elements. Ordered
in this denition means that each element has a position in the list. (We will not use ordered
in this context to mean that the list elements are sorted by value.) Each list element has a
data type. Implement a simple list, where, all elements of the list have the same data type,
although there is no conceptual objection to lists whose elements have differing data types if
the application requires it. The operations dened as part of the list ADT do not depend on
the elemental data type. For example, the list ADT can be used for lists of integers, lists of
characters, lists of payroll records, even lists of lists.
Make sure that your abstract list class contains all the functions mentioned below:

List() // Default constructor

virtual List() // Base destructor

virtual void clear() = 0;

virtual void insert(const E& item) = 0;

virtual void append(const E& item) = 0;

virtual E remove() = 0;

virtual void moveToStart() = 0;

virtual void moveToEnd() = 0;

virtual void prev() = 0;

virtual void next() = 0;

virtual int length() const = 0;

virtual int currPos() const = 0;

virtual void moveToPos(int pos) = 0;

virtual const E& getValue() const = 0;


Here E is an abstract data type defined through templates.
Question: There are two standard approaches to implementing lists, the array-based
list, and the linked list. In this lab, our focus is on array based implementation. Write a
class named AList, AList inherits from abstract class List and so must implement all of
the member functions of List. Write a main function to demonstrate the functionality
of your AList class.
Use templates to define an abstract AList.

You might also like