publicclass Link {
publiclong lData;
public Link next;//reference to next LinkpublicLink(long lData){
this.lData=lData;
}
publicvoiddisplayLink1(){
System.out.print("{"+lData+"}");
}
}
publicclass FirstLastList {
private Link first;
private Link last;
publicFirstLastList(){
first=null;
last=null;
}
public boolean isEmpty(){
return (first==null);
}
publicvoidinsertFirst(long dd){//insert at front of list
Link newLink = new Link(dd);
if(isEmpty()){
last=newLink;
}
newLink.next=first;
first=newLink;
}
publicvoidinsertLast(long dd){
Link newLink = new Link(dd);
if(isEmpty()){
first=newLink;
}
else{
last.next=newLink;
}
last=newLink;
}
publiclongdeleteFirst(){
long temp=first.lData;
if(first.next==null){
last = null;
}
first=first.next;
return temp;
}
publicvoiddisplayList(){
Link current =first;
while(current!=null){
current.displayLink1();
current=current.next;
}
}
}