next up previous contents
Next: The CHAR_SLLIST Implementation Details: Up: The CHAR LIST DATA Previous: The CHAR LIST DATA

The Basic Design:

class CHAR_LIST_CORE{
    friend class CHAR_CELL_CORE;
    friend istream& operator>>(istream& in,CHAR_LIST_CORE& A)
      {A.grab(in); return(in);};
    friend istream& operator>>(istream& in,CHAR_LIST_CORE* A)
      {A->grab(in); return(in);};
    friend ostream& operator<<(ostream& out,const CHAR_LIST_CORE& A)
      {A.print(out); return(out);};
    friend ostream& operator<<(ostream& out,const CHAR_LIST_CORE* A)
      {A->print(out); return(out);};
  public:
    virtual int is_empty() = 0;
    virtual void delete_element(CHAR target_key) = 0;
    virtual void search_element(CHAR search_key) = 0;
    virtual void build_list(CHAR *A,int size) = 0;
    virtual int get_number_elements() = 0;
    virtual void insert_after(CHAR before,CHAR after) = 0;
    virtual void insert_before(CHAR after,CHAR before) = 0;
    virtual istream& grab(istream& in) = 0;
    virtual ostream& print(ostream& out) const = 0;
  protected:
    char *name;    
  };

The singly linked list is then derived from this parent as follows:

class CHAR_SLLIST : public CHAR_LIST_CORE{
    friend class CHAR_SL_CELL;
    friend class CHARSLLISTFIter;
  public:
    CHAR_SLLIST(char *name_in);
    CHAR_SLLIST(CHAR_SLLIST&);
    ~CHAR_SLLIST();
    CHAR_SLLIST& operator=(const CHAR_SLLIST&);
    // agents
    int is_empty(){return(head==NULL);};
    void delete_element(CHAR target_key);
    void search_element(CHAR search_key);
    void build_list(CHAR *A,int size);
    int get_number_elements();
    void insert_after(CHAR before_element,CHAR new_element);
    void insert_before(CHAR after_element,CHAR new_element);
    void mergesort();
    istream& grab(istream& in);
    ostream& print(ostream& out) const;
  protected:
    CHAR_SL_CELL *head;
    CHAR_SL_CELL* get_element_address(CHAR search_key);
    CHAR_SL_CELL* get_before_element_address(CHAR search_key);
    CHAR_SL_CELL* get_after_element_address(CHAR search_key);
  };

The doubley linked list is also derived from this core:

  
class CHAR_DLLIST : public CHAR_LIST_CORE{
    friend class CHAR_DL_CELL;
    friend class CHARCLLISTFIter;
    friend class CHARCLLISTBIter;
    friend class CHARDLLISTFIter;
    friend class CHARDLLISTBIter;    
    friend istream& operator>>(istream& in,CHAR_DLLIST& A)
      {A.grab(in); return(in);};
    friend istream& operator>>(istream& in,CHAR_DLLIST* A)
      {A->grab(in); return(in);};
    friend ostream& operator<<(ostream& out,const CHAR_DLLIST& A)
      {A.print(out); return(out);};
    friend ostream& operator<<(ostream& out,const CHAR_DLLIST* A)
      {A->print(out); return(out);};
  public:
    CHAR_DLLIST(char *name_in);
    CHAR_DLLIST(CHAR_DLLIST&);
    ~CHAR_DLLIST();
    CHAR_DLLIST& operator=(const CHAR_DLLIST&);
    // agents
    int is_empty(){return(head==NULL);};
    void delete_element(CHAR target_key);
    void search_element(CHAR search_key);
    void build_list(CHAR *A,int size);
    int get_number_elements();
    void insert_after(CHAR before_element,CHAR new_element);
    void insert_before(CHAR after_element,CHAR new_element);
    void mergesort();
    istream& grab(istream& in);
    ostream& print(ostream& out) const;
  protected:
    char *name;
    CHAR_DL_CELL *head;
    CHAR_DL_CELL *end;
    CHAR_DL_CELL* get_element_address(CHAR search_key);
    CHAR_DL_CELL* get_before_element_address(CHAR search_key);
    CHAR_DL_CELL* get_after_element_address(CHAR search_key);
  };



Jim Peterson
1999-04-22