class (II) - Example Array-based List List A collection of...

Info icon This preview shows pages 1–3. Sign up to view the full content.

10 Example: Array-based List List : A collection of elements of the same type. Operations on a list 1. Create a list (empty list) 2. Determine if the list is empty. 3. Determine if the list is full. 4. Find the size (length) of the list. 5. Destroy, or clear, the list. 6. Determine whether an item is contained in the list. 7. Insert an item (at the default location or a given location). 8. Remove an item (from the default location, or a given location, or given value). 9. Retrieve an item from the list (at the default location, or the specified location). 10. Search the list for a given item. Implementation consideration 1: How to store the list in the computer’s memory? - In this example, we store the list items using an array. Implementation consideration 2: We want the program codes to be reusable for different data types, e.g. int , double , fraction , and etc. - Develop generic codes using template - In Java, this is called generic class (or generic programming)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

11 // filename: arrayListType.h #ifndef ARRAY_LIST_TYPE_H #define ARRAY_LIST_TYPE_H template <class elemType> class arrayListType { protected: elemType *list; //array to hold list elements int length; //no. of elements in the list int maxSize; //physical size of array public: arrayListType(int size = 100); //constructor, default size = 100 arrayListType(const arrayListType<elemType>& other); //copy constructor ~arrayListType(); //destructor, deallocate the memory occupied by the array //A user defined destructor is necessary if the object //instance contains dynamically allocated memory. //accessor functions bool isEmpty() const; bool isFull() const; int listSize() const; int maxListSize() const; void print() const; virtual int search(const elemType& item); void retrieve(int loc, elemType& item); arrayListType<elmType>& operator= (const arrayListType<elmType>& other); //mutator functions void clearList(); virtual void insert(const elemType& item); virtual
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '14
  • VAN
  • ElemType, class elemType

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern