/* File: list4.h
  
   A simple linked list ADT in C++.
*/

#ifndef _list4_h
#define _list4_h


/* Data in each node is a string.
   If you change this, you must also change strcmp and
   strdup to the appropriate functions.  Also, memory
   allocation and deallocation must be changed.
*/

typedef char *data ;


/* Each node in the linked list is a ListNode object */
class ListNode {
   friend class List ;   

public:
   data item;		/* data in each node */
   
private:
   ListNode *next ;	/* pointer to next node in the linked list */
   ListNode() ;		/* default constructor */
   ListNode(data) ;	/* alternate constructor */
   ~ListNode() ;	/* destructor */
} ;


/* We should have done this before: define the position in the
   linked list as a type.  As before, the position is a pointer
   to the node before the node we are interested in. 
*/
typedef ListNode *position ;


class List {
public:
   List() ;			/* default constructor */
   ~List() ;			/* destructor */
   void Append(data) ;		/* Add item to the end of the list */
   void Prepend(data) ;		/* Add item to the beginning of the list */
   void Delete(position) ; 	/* Remove node at given position */
   int IsMember(data) ;		/* Item on the list? 0=No 1=Yes */
   void Concatenate(List *) ;	/* Add list to the end of this one */
   List *Duplicate() ;		/* Return copy of this list */
   void Print() ;		/* Print the contents of this list */
   int Count() ;		/* Return number of items in this list */

   /* The following 3 returns copies of the strings */
   data FirstItem() ;		/* First item on the list */
   data LastItem() ;		/* Last item on the list  */
   data ItemAt(position) ; 	/* Return item at given position */  

   position FirstPos() ;	/* Position of the first item */
   position NextPos(position) ; /* Position after the given one */
   position Locate(data) ;	/* Position of item on list. (see doc) */ 

protected:
   ListNode header ;
   int count ;
   ListNode *last ;
} ;

#endif
