/******************************************************************************/ /* MAT 373 Generic Linked List Data Structure Mantharam */ /******************************************************************************/ /* Project 2 - Part I */ /******************************************************************************/ /* IMPLEMENT ALL THE FUNCTIONS IN THE HEADER FILE. */ /* IMPORTANT NOTE: operator << MUST BE OVERLOADED. DO NOT MODIFY THIS FILE. */ /******************************************************************************/ /* */ /* WRITE A MAIN PROGRAM TO TEST ALL YOUR IMPLEMENTATION: */ /* (1) TO TEST THE GENERIC NATURE, DECLARE LINKED LIST WITH DIFFERENT DATA */ /* TYPES. */ /* (2) CREATE LINKED LISTS BY INSERTING ITEMS IN THE FRONT, AT THE END, AND */ /* IN ORDER. */ /* (3) CALL ALL OTHER FUNCTIONS WITH THESE OBJECTS AND TEST THEIR CORRECTNESS.*/ /* EVERY TIME YOU TEST A FUNCTION, PRINT THE LIST BEFORE AND AFTER. */ /* FOLLOW THE SAMPLE CODE GIVEN IN TestingDate.cpp */ /* */ /******************************************************************************/ #ifndef LLIST_H #define LLIST_H #include template class LList { friend ostream & operator << (ostream &, LList &); private: struct NodeType { ItemType item; NodeType *next; }; typedef NodeType * NodePtr; NodePtr First, Last; public: int PrintLength; // USED TO SET THE NUMBER OF ITEMS PRINTED IN EACH ROW LList(); void FirstInsert(ItemType &); // POST: FirstInsert(...) inserts the very first item in a linked list void FrontInsert(ItemType &); // PRE: FrontInsert(...) assumes the linked list is non-empty. // POST: FrontInsert(...) inserts the item at the front of a linked list void EndInsert(ItemType &); // PRE: EndInsert(...) assumes the linked list is non-empty. // POST: EndInsert(...) adds the item at the end of a linked list void InOrderInsert(ItemType &); // PRE: InOrderInsert(...) assumes the linked list is non-empty. // InOrderInsert(...) assumes that the linked list has // items in ascending order. Uses the operators <=, >= and > on ItemType // POST: Maintains the order after inserting the new item int In(ItemType &); // POST: Returns true if the item is in the linked list and false otherwise. ItemType FirstItem(); // PRE: Assumes the linked list is non-empty // POST: Returns the first item in the linked list ItemType LastItem(); // PRE: Assumes the linked list is non-empty // POST: Returns the last item in the linked list bool Delete(ItemType &); // POST: If the item is in the linked list, the item is removed from the // linked list and the functions returns 'true'. If the item is not // in the linked list then the function returns 'false'. bool IsEmpty(); // POST: Returns true if the linked list is empty and false otherwise. void Clear(); // POST: Deletes all items in the list and resets the list as an empty list. ~LList(); }; #endif