Lecture 15 Section 6.1 Mon, Feb 26, 2007 Lists Lecture 15 Section 6.1 Mon, Feb 26, 2007
Lists A list is an ordered set of elements {a1, …, an} The indexing begins at 1, not 0. a1 is at the head of the list. an is at the tail of the list. The elements ai may be of any type. But they must all be of the same type. The structure is homogeneous. A list is a generalization of an array.
List ADT: List Attributes A list has a size elements a1 through asize.
List ADT: Constructors List(int sz); List(int sz, const T& value); List(const List& lst);
List ADT: Destructor Destructor ~List();
List ADT: Inspectors Inspectors T getElement(int pos) const; int size() const; bool isEmpty() const;
List ADT: Mutators Mutators void setElement(int pos, const T& value); void insert(int pos, const T& value); void remove(int pos); void makeEmpty();
List ADT: Mutators Additional Mutators void pushFront(const T& value); void pushBack(const T& value); T popFront(); T popBack();
List ADT: Facilitators void input(istream& in); void output(ostream& out) const;
List ADT: Operators Operators List& operator=(const List& lst); T& operator[](int pos);
List ADT: Other Member Functions void swap(List& lst); int search(const T& value) const; void sort(); bool isValid() const;