Write code for if you have a doubly-liked list that has no tail and how you would remove the tail and what would be the size of it? (Java for Data Structures and Algorithms)
//let structure of doubly linked list node be
class double_node
{
int data;
double_node next,prev;
}
//now
//method to remove tail of doubly linked list, where head is
passed
//process to removing tail node from given linked list
double_node remove_tail(double_node head)
{
if(head==null || head.next ==null)//if less than or
equal to one node is present
return null;
double_node temp=head;
while(temp.next!=null)//finding tail node
{
temp=temp.next;
}
//now temp points to tail node
temp.prev.next=null;//removing link to tail node
temp.prev=null;
//size of double linked list is reduced by 1
return head;
}
Get Answers For Free
Most questions answered within 1 hours.