1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
//Here is the complete header file:
#ifndef LINKEDLISTTYPE_H
#define LINKEDLISTTYPE_H
#include <iostream>
#include <cassert>
using namespace std;
template<class Type>
class linkedListType;
template<class Type>
ostream& operator<<(ostream, const linkedListType<Type>&);
template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};
template<class Type>
class linkedListType
{
friend ostream& operator<< <>(ostream&, const linkedListType<Type>&);
public:
const linkedListType<Type>& operator=
(const linkedListType<Type>&);
//Overload the assignment operator.
void initializeList();
//Initializes the list to an empty state.
//Postcondition: first = NULL, last = NULL;
// count = 0;
bool isEmptyList();
//Function to determine whether the list is empty.
//Postcondition: Returns true is the list is empty;
// otherwise returns false.
int length();
//Function to return the number of nodes in the list.
//Postcondition: The value of count is returned.
void destroyList();
//Function to delete all the nodes from the list
//Postcondition: first = NULL, last = NULL,
// count = 0;
Type front();
//Function to return the first element of the list.
//Precondition: The list must exist and must not be empty.
//Postcondition: If the list is empty, then the
// progream terminates, otherwise,
// the first element of the list is returned
Type back();
//Function to return the last element of the list.
//Precondition: The list must exist and must not be empty
////Postcondition: If the list is empty, then the
// progream terminates, otherwise,
// the last element of the list is returned
bool search(const Type& searchItem);
//Function to determine whether searchItem is in the list
//Postcondition: Returns true of searchItem is found in the list
// otherwise it returns false
void insertFirst(const Type& newItem);
//Function to insert newItem in the list
//PostCondition: first points to the new list and newItem is
// is inserted at the beginning of the list
void insertLast(const Type& newItem);
//Function to insert newItem at the end of the llist
//PostCondition: first points to the new list and newItem is
// is inserted at the end of the list, and last points
// to the last node in the list
void deleteNode(const Type& deleteItem);
//Function to delete deleteItem from the list
//Postcondition: IF found, the node containing deleteItemis deleted
// from the list, first point to the first node, and last
// points to the last nodeof the updated list.
void deleteAll(const Type& deleteItem);
//Delete all occurrences of a given element
void deleteSmallest();
//Find and delete the node with the smallest info
linkedListType();
//default constructor
//Initializes the list to an empty state.
//Postcondition: first = NULL, last = NULL,
// count = 0;
linkedListType(const linkedListType<Type>& otherList);
//copy constructor
~linkedListType();
//destructor
//Deletes all the nodes from the list.
//Postcondition: The list object is destroyed
protected:
int count; //variable to store the number of elements
// in the list
nodeType<Type> *first; //pointer to the first node of the list
nodeType<Type> *last; ////pointer to the last node of the list
private:
void copyList(const linkedListType<Type>& otherList);
//Function to make a copy of otherlist.
//Postcondition: A copy of otherList is created
// and assigned to this list
};
#endif
|