HELP WITH LINKED LIST

So I have a linked list:
1
2
3
4
5
6
7
class List{
public:
   List();
   List(const List&p);
   I have more methods
private:
   struct Node{
       Node number;
       Node* next;
    };
    Node* a_first;
}

---------------------------------

It all works perfectly but I have problems with the constructor copy. I have to use the copy constructor
1
2
3
4
5
6
7
8
9
10
11
12
List::List(const List &c){
    Node *last, *p
    p = c.a_first;
    last = NULL;
    while (p != NULL) {
         last=p;
         Node* b=new Node;
         b->number=p->number;           
         ant->next=b;
         p=p->next;
    }
}
Last edited on
What precisely are the problems you're referring to?

Things I've noticed:
Node *last is useless.
new Node; should be new Node();
List::a_first is not assigned in the copy constructor.
why even have a copy constructor for a linked list?
Because I want to copy the list.
List v;
List b(v);
b.show();
The problem is that it doesn't copy the list and I don't know what is wrong.

Thanks
Last edited on
I assume my post answered your question then?
What is ant on line 9?
Topic archived. No new replies allowed.