1st Class LIST ADT

This is a discussion on 1st Class LIST ADT within the C++ Programming forums, part of the General Programming Boards category; Hi all, I am tyring to create a first class ADT List. Unfortunately, i am getting a number of syntax ...

  1. #1
    Unregistered
    Guest

    1st Class LIST ADT

    Hi all,
    I am tyring to create a first class ADT List. Unfortunately, i am getting a number of syntax errors that i don't understand. The first one concerns "list L = *this" . "cannot convert from
    'class LIST' to 'struct LIST::list_node *'" If someone has a better way to do the deletelist() function feel free to sugest it. Any help is appreciated! Thanks!



    class LIST
    {
    private:
    typedef int boolean;
    typedef char data;
    struct list_node
    {
    data info;
    list_node *next;
    };
    typedef list_node list_head;
    typedef list_head *list;

    void deletelist()
    {
    list L = *this;
    list_node* T;

    while(L != NULL)
    {
    T = L;
    L = L->next;
    delete T;
    }
    }
    public:
    LIST(const LIST &rhs)
    {
    *this = rhs;
    }
    LIST& operator=(const LIST& rhs)
    {
    list_node* L;
    data the_data = rhs->next->info;

    if(this == &rhs)
    return *this;
    deletelist();

    L = copy(rhs);
    return *this;

    }
    ~LIST()
    {deletelist();}

    void printlist (list);
    void printlist_NR (list);
    list nullist(void);
    boolean null(list);
    data car(list);
    list cdr(list);
    list cons(data, list);
    data read_element(void);
    list readlist_element(void);
    list readlist_element_NR(void);
    list readlist(void);
    list readlist_NR(void);
    int longer(list, list);
    list delete3(data, list);
    list del_all(data, list);
    list copy(list);
    list rotate(list);
    list list_reverse_NR(list);
    list list_reverse(list);
    int length(list);
    int length_NR(list);
    list append(list, list);
    list append_NR(list, list);

    }; // end of class

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    list is a typedef of a list_node but *this is a LIST. I don't think it's necessary to try and assign *this to list L, you shouldn't need a copy. Use a copy of the head of your list to walk through it deleting. Something like

    while(list_iterator->next!=NULL)
    {
    list_copy=list_iterator;
    list_iterator=list_iterator->next;
    delete list_copy;
    }

    where list_iterator is initially a copy of your head pointer.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  4. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  5. link list
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 12-13-2001, 05:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21