Answer to Question #244134 in C++ for Ally

Question #244134
Implement destructor for the following class :

class List{
public:
int item;
int pos;
List* nextNode;
List()
{
this->pos=0;
}
List(int pos)
{
this->pos=pos;
}
List(int item,int pos)
{
this->item=item;
this->pos=pos;
}
List(List &list)
{

this->item=list.item;
this->pos=list.pos;

this->nextNode=list.nextNode;

}

};
1
Expert's answer
2021-09-29T01:18:57-0400
class List{


public:


	int item;


	int pos;


	List* nextNode;
	//destructor 
	~List(){
		if(nextNode!=NULL){
			delete nextNode;
		}
		
	}


	List()


	{


		this->pos=0;


	}


	List(int pos)


	{
		nextNode=NULL;
		this->pos=pos;


	}


	List(int item,int pos)


	{
		nextNode=NULL;
		this->item=item;


		this->pos=pos;


	}


	List(List &list)


	{
		nextNode=NULL;
		this->item=list.item;


		this->pos=list.pos;


		this->nextNode=list.nextNode;


	}


};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS