void addEnd(int data)
{
Node temp = new Node();
temp.data=data;
if(this.link==null && this.data==0)
{ //if the entire linked list is empty
this.data=data;
}
else
{
Node ptr=this;
while(ptr.link!=null)
{
ptr=ptr.link;
}
ptr.link=temp;
}
temp=null;
}
Solved PYQs, Programs, Circuits & Guides
void addEnd(int data)
{
Node temp = new Node();
temp.data=data;
if(this.link==null && this.data==0)
{ //if the entire linked list is empty
this.data=data;
}
else
{
Node ptr=this;
while(ptr.link!=null)
{
ptr=ptr.link;
}
ptr.link=temp;
}
temp=null;
}