Hey everyone,
I am currently working on a project to create a List ADT that has the following public interface:
+ size( ) : integer
o Returns the number of elements currently stored in the list.
o Postcondition: Returns 0 if empty otherwise returns the number of elements.
+ add( element: ElementType )
o Add an element to the list.
o Precondition: “element” does not already exist in the list. This is to say: no duplication allowed.
o Postcondition: “element” has been added to the end of the list.
o Throws an exception if “element” already exists in the list.
+ remove( element: ElementType ) : ElementType
o Remove this element from the list.
o Precondition: List is not empty.
o Postcondition: If the element is found in the list, it is removed from the list and returned. If the element is not found in the list, “null” is returned.
o Throws an exception if list is empty.
+ removeAll( )
o Remove all elements from the list.
o Postcondition: size( ) returns 0.
+ get( element: ElementType ) : ElementType
o Returns this element.
o Precondition: List is not empty.
o Postcondition: If the element is found in the list, it is returned. If the element is not found in the list, “null” is returned.
o Throws an exception if list is empty.
I want to make my implementation as flexible as possible in terms of the “type” of the elements in the list.Also make use of “typedef” and implement the List ADT using a reference or pointer-based data structure.
And make unit test of the ADT class .
Here is what I got so far and I am not sure if i am doing it right.So i would appreciate it if you help me figure this out.
Thanks,