Question: I have this Java code to delete the last element in a circular double linked list. I need help writing a method that delete the

I have this Java code to delete the last element in a circular double linked list. I need help writing a method that delete the first element, and a method that delete an element at a given position

////////////////////////////////////////////////////

public class CDLinkedList {

private static class Node{ private E Data; private Node next; private Node prev; public Node(Node prev,E Data,Node next){ this.Data=Data; this.next=next; this.prev= prev; } public E getdata(){ return Data; } public Node getnext(){ return next;} public void setnext(Node next){this.next=next;} public void setdata(E Data){ this.Data=Data; } public Node getprev(){ return prev;} public void setprev(Node prev){ this.prev=prev; } }

private Node first; private Node last; private int size;

public void deleteLast(){ if (size == 0) { System.out.println("Empty list"); return; } else if (size==1) { last = first; first= null; return; } last.prev.setnext(first); first.setprev(last.prev); last= last.prev; size--;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!