Код: Выделить всё
struct node
{
int value;
node *next;
};
class cList
{
public:
cList();
~cList();
void Add(int value);
void Delete();
void DeleteAll();
void Print();
int GetCount() const;
private:
node *Head;
node *Tail;
int itsCount;
};
cList::cList()
{
Head=Tail=NULL;
itsCount=0;
}
cList::~cList()
{
DeleteAll();
}
void cList::Add(int value)
{
node *temp=new node;
temp->value=value;
temp->next=NULL;
if(Head!=NULL)
{
Tail->next=temp;
Tail=temp;
}
else
{
Head=Tail=temp;
}
itsCount++;
}
void cList: :D elete()
{
if(itsCount>0)
{
node *temp=Head;
Head=Head->next;
delete temp;
itsCount--;
}
else
{
cout<<"!!!ERROR: The list is empty. Nothing to delete!\n";
}
}
void cList: :D eleteAll()
{
if(itsCount>0)
{
while(Head!=NULL)
Delete();
}
else
{
cout<<"!!!ERROR: The list is empty. Nothing to delete!\n";
}
}
void cList::Print()
{
if(itsCount>0)
{
node *temp=Head;
while(temp!=NULL)
{
cout<<temp->value<<" ";
temp=temp->next;
}
cout<<"\n\n";
}
else
{
cout<<"The list is empty\n";
}
}
int cList::GetCount() const
{
return itsCount;
}
Кому не турдно, напишите как это сделать, и если можно с комментариями.