Open main menu

CDOT Wiki β

Changes

Project A3 20141 - OOP344

732 bytes removed, 08:22, 3 April 2014
Class: List, Files [list.h], Test: 1: Updated templated list
=== Class: List<T>, Files [list.h], Test: 1 ===
A templated linked list class. Similar to IntList. Similarly to IntList, because it needs to be able to set the next pointer on Uses ListNode<T> objects, this class '''may''' need to be as a friend of the ListNode<T> node class (this depends on how you implement these classes).
The exact specs follow:==== Recommended Members ====* Pointer to head node in list* Current size (number of nodes) of list
==== Internal Variables Public Functions ====; ListNode<T>* _headConstructor: Does not accept parameters. Initializes list to safe empty state. ; size: Size getter. Const function. Does not receive parameters. Should return number of nodes in list.; head: The Head getter. Const function. Returns pointer to head node in list. ; push: Adds a new node to the '''end of the list'''. I'll say that again, '''END OF THE LIST'''. '''Important'''. Receives a const T reference. Should The new node's value should be NULL when set to the received reference.; pop: Destroys the '''last node in the list is empty'''. I'll say that again, '''LAST NODE IN THE LIST'''. Does not receive any arguments. Does not return anything.; int _sizeclear: The number of elements currently Removes all nodes in the list. Has no effect if the list is empty. Does not accept parameters. Does not return anything.
==== Public Functions ====; List()Destructor: Default constructor. Should set size to 0 and head to NULL.; List(const List<T>& src): Copy constructor. Should copy the list of nodes managed by '''src'''. This means ensure that an entirely new list of nodes must be created, one node for each node managed by '''src''', and the value held all memory allocated by each of those nodes must '''equal''' the value held by the corresponding node managed by '''src'''. When this constructor is finished, the size of the current list should be the same as the size of srchas been deallocated.<br/><br/>'''TIP:''' After initializing the current object You are encouraged to a '''safe and empty state''', don't forget that you may call '''any member function''' that use the current list has!; List<T>& operator=(const List<T>& src): Assignment operator. Should behave similarly functions available to the copy constructor. '''ADDITIONALLY:''' Should do '''NOTHING''' in the case of '''self-assignment''' (ie List<int> x; x = x;). If taking action, should clear the list of all nodes before creating new ones ('''make sure that you do NOT leak memory!'''). Should return a reference to the current object.
; int size() constStandard Assignment Operator: Size getterClears this list of all nodes. Returns Then, refills list with the current value same number of nodes as in the size member.; ListNode<T>* head() const: Head gettersource list. Returns the current value Value of the head pointer.; void push(const T& v): Adds a each new node to should equal the '''end value of the list''' holding the value v. Should increment size.; void pop(): Destroys the last corresponding node in the source list. Should do '''NOTHING''' if not alter object in the list is currently emptycase of self-assignment. Should decrement size if a node was destroyed. '''NOTE:''' If return a node was destroyed, make sure that '''ANY POINTERS POINTING TO IT''', that your code has access reference to, are set to NULLthe current object.; void clear()Copy Constructor: Destroys all nodes in the Initializes object to safe state then copies source list. Has no effect if the into current list is currently empty. When this function is finished, head should point Similar to NULL and size should be 0assignment operator.
== Submission ==
Please only submit '''ONCE YOUR CODE SUCCESSFULLY PASSES ALL TESTS!''' This includes the '''COMMON SENSE TEST''' which is the test that you perform '''yourself''' on your own code to ensure that it matches with what is required '''in the spec'''. Please see your instructor's specific instructions on how to submit.