topic description
run the main function and look at the output (the answer should be 0 448)
topic source
edu training course
related code (part provided in the title)
the following is the content of LinkedList.h
class LinkedList {
public:
//
struct Node{
int data;
Node *next;
Node(int a=0,Node *b=nullptr):data(a),next(b){}
};
private:
Node *head;//
int size; //
public:
//
LinkedList();
//
LinkedList(const LinkedList&rhs);
//
LinkedList(int const a[],int n);
//nvalue
LinkedList(int n,int value);
//
~LinkedList();
//
int getSize()const{return size;}
};
main.cpp is as follows
< H1 > include < iostream > < / H1 > < H1 > include "LinkedList.h" < / H1 >using namespace std;
int A [] = {100 int 200, 400, 400, 800, 1 600};
int main () {
LinkedList a,b(A,4);
LinkedList c(b),d(8,6);
cout<<a.getSize()<<" "<<b.getSize()<<" "<<c.getSize()<<" "<<d.getSize()<<endl;
return 0;
}
Constructors and destructors I wrote
< H1 > include "LinkedList.h" < / H1 > LinkedList::LinkedList ()
{head=nullptr;
size=0;
}
LinkedList::LinkedList (const LinkedList&rhs)
{
Node*p1=head;
p1=new Node;
p1->next=nullptr;
Node*p2=rhs.head->next;
while(p2)
{p1->next=new Node;
p1=p1->next;
p1->data=p2->data;
p1->next=nullptr;
p2=p2->next;
}
size=rhs.getSize();
}
LinkedList::LinkedList (int const a [], int n)
{Node*p=head;
Node*temp;
for (int iPp)
{temp=new Node;
temp- > data=a [I];
temp- > next=p- > next;
p-> next=temp;
}
size=n;
}
LinkedList::LinkedList (int njinint value)
{Node*p=head;
Node*temp;
for (int iPp)
{br IPP)
}
size=n;
}
LinkedList::~LinkedList ()
{if (size==0)
{delete head;
head=nullptr;
return;
}
while (head- > nextroomnullptr)
{Node*temp=head;
head=head- > next;
delete temp;
}
delete head;
head=nullptr;
size=0;
}
although this code has been compiled and passed, it has not been output. I want to know why