Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
doubly linked list get first and last element?
dear all ,i want to write two diffirent method for doubly linked list , one for get first element and the second ont to get the las element i try with these code but it give me an error
package doublelinked;
public class doublee {
int size =0;
Node head = null;
Node tail = null;
class Node{
int data;
Node next;
Node previous;
public Node(int data){
this.data = data;
next = null;
previous = null;
}
}
public Node addAtStart(int data){
System.out.println("Adding Node " + data + " at the start");
Node n = new Node(data);
if(size==0){
head = n;
tail = n;
}else{
n.next = head;
head.previous = n;
head = n;
}
size++;
return n;
}
public Node addAtEnd(int data){
System.out.println("Adding Node " + data + " at the End");
Node n = new Node(data);
if(size==0){
head = n;
tail = n;
}else{
tail.next = n;
n.previous = tail;
tail =n;
}
size++;
return n;
}
public node getfirst();
if(isEmpty()) return null;
return head.getNext;
}public node getlast();
if(isemty(()) return null;
return tail.getNext;
}
Be the first to answer this question.