Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************
- Author: Dr. Daniel Spiegel, Updated by: Trisha Badlu
- Creation Date: 19 April 2017
- Due Date: 26 April 2017
- Assignment: #4
- Filename: LinkedList.h
- Course: CSC136 - 020
- Professor Name: Dr. Spiegel
- Purpose: The purpose of this file is to declare each
- prototype of the LinkedList class and to
- define an iterator.
- ***************************************************************/
- // File: LinkedList.h
- // LinkedList class with node and listIterator class
- // Recognizes Multiple Copies of Items During Insertion
- // Returns pointer to data if data found in list during insertion
- // does not insert item more than once
- // Find returns pointer to data if found.
- #ifndef _LinkedList_
- #define _LinkedList_
- #include <assert.h>
- #include <iostream>
- using namespace std;
- // Need to prototype template classes if they are to be friends
- template <typename eltType> class LinkedList;
- template <typename eltType> class listItr;
- template <typename eltType> class node
- {private:
- node(eltType info, node* link = NULL ) : data(info), next(link) {};
- eltType data;
- node* next;
- friend class LinkedList<eltType>;
- friend class listItr<eltType>;
- };
- template <typename eltType> class LinkedList
- {
- public:
- /***************************************************************
- Function name: LinkedList (mutator)
- Description: Creates an empy LinkedList
- Parameters: none
- Return Value: none
- ***************************************************************/
- LinkedList();
- /***************************************************************
- Function name: LinkedList (mutator)
- Description: Creates a deep copy of a LinkedList
- Parameters: LinkedList& - cl (import/export)
- Return Value: none
- ***************************************************************/
- LinkedList(LinkedList& cl);
- /***************************************************************
- Function name: LinkedList (mutator)
- Description: Destroys a LinkedList
- Parameters: none
- Return Value: none
- ***************************************************************/
- ~LinkedList();
- /***************************************************************
- Function name: operator= (facilitator)
- Description: Assign another LinkedList to this LinkedList
- Parameters: LinkedList& - cl (import/export)
- Return Value: LinkedList - *this
- ***************************************************************/
- LinkedList& operator=(const LinkedList &cl);
- /***************************************************************
- Function name: empty (facilitator)
- Description: Checks if a LinkedList is empty
- Parameters: none
- Return Value: bool - true (if empty)
- false (if not empty)
- ***************************************************************/
- bool empty();
- /***************************************************************
- Function name: find (facilitator)
- Description: Checks if an object of eltType already exists in
- a LinkedList
- Parameters: const eltType& - elt (import/export)
- Return Value: eltType - &p->data (if found)
- NULL (if not found)
- ***************************************************************/
- eltType* find(const eltType &elt);
- /***************************************************************
- Function name: orderedInsert (mutator)
- Description: Inserts an object of eltType into a LinkedList
- alphanumerically
- Parameters: const eltType& - elt (import/export)
- Return Value: eltType - &p->data (if object already exists)
- NULL (if object is inserted)
- ***************************************************************/
- eltType *orderedInsert(const eltType &elt);
- /***************************************************************
- Function name: remove (mutator)
- Description: Removes an object of eltType from the LinkedList,
- assuming that the specified object already exists
- within the LinkedList
- Parameters: const eltType& - elt (import/export)
- Return Value: none
- ***************************************************************/
- void remove(const eltType &elt);
- /***************************************************************
- Function name: countNodesInList (facilitator)
- Description: Counts the amount of nodes that exist in a
- LinkedList
- Parameters: none
- Return Value: int - total amount of nodes starting at head
- ***************************************************************/
- // Quick example of recursion
- int countNodesInList() const;
- private:
- // linked list pointer
- node<eltType>* head;
- /***************************************************************
- Function name: copy (mutator)
- Description: Gets a deep copy of a node
- Parameters: node<eltType>* - l (import/export)
- Return Value: node<eltType> - first
- ***************************************************************/
- node<eltType>* copy(node<eltType> *);
- /***************************************************************
- Function name: destroy (mutator)
- Description: Free nodes of a LinkedList
- Parameters: node<eltType>* - l (import/export)
- Return Value: none
- ***************************************************************/
- void destroy(node<eltType> *);
- /***************************************************************
- Function name: countNodes (facilitator)
- Description: Counts the amount of nodes that exist in a
- LinkedList
- Parameters: node<eltType>* - l (import/export)
- Return Value: int - total amount of nodes starting at head
- ***************************************************************/
- int countNodes(node<eltType> *) const;
- /*
- // Linked list to ostream
- friend ostream& operator<< <>(ostream&, LinkedList<eltType>);
- */
- // Needed to use a list iterator
- friend class listItr<eltType>;
- };
- template <typename eltType>
- /***************************************************************
- Function name: operator<< (facilitator)
- Description: Prints out a LinkedList
- Parameters: ostream& - os (import/export)
- const LinkedList<eltType> - &l (import/export)
- Return Value: ostream& - os
- ***************************************************************/
- ostream& operator<<(ostream &os,const LinkedList<eltType> &l);
- // Set up an iterator;
- // an object that provides a pointer to a linked list (in this case)
- template <typename eltType> class listItr
- {
- public:
- /***************************************************************
- Function name: listItr (mutator)
- Description: Creates a list iterator
- Parameters: LinkedList<eltType>& - l
- Return Value: none
- ***************************************************************/
- listItr( LinkedList<eltType> &l);
- /***************************************************************
- Function name: listItr (mutator)
- Description: Creates from a const reference to a LinkedList
- Parameters: LinkedList<eltType>& - l
- Return Value: none
- ***************************************************************/
- listItr(const LinkedList<eltType> &l);
- /***************************************************************
- Function name: start (facilitator)
- Description: Points to first node in LinkedList
- Parameters: none
- Return Value: none
- ***************************************************************/
- void start();
- /***************************************************************
- Function name: more (facilitator)
- Description: Checks if the current node is NULL
- Parameters: none
- Return Value: bool - true (if node isn't NULL)
- false (if node is NULL)
- ***************************************************************/
- bool more() const;
- /***************************************************************
- Function name: next (facilitator)
- Description: Points to the next node in a LinkedList
- Parameters: none
- Return Value: none
- ***************************************************************/
- void next();
- /***************************************************************
- Function name: value (inspector)
- Description: Gets the value of the current node
- Parameters: none
- Return Value: eltType& - curr->data
- ***************************************************************/
- eltType &value();
- /***************************************************************
- Function name: value (inspector)
- Description: Gets the value of the current node
- Parameters: none
- Return Value: eltType& - curr->data
- ***************************************************************/
- const eltType &value() const;
- private:
- const LinkedList<eltType> &itr;
- node<eltType> *curr;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement