Sunday, February 8, 2009

it123

a.) Definition:
DOUBLE -ENDED LINKED LIST-it is a first and last reference. It can be the
arrangement of such qualities in every inputs that are available.



b.) illustration:

Double-ended linked list












c.)code/algorithm:


//Implementation of Double-Ended List
//Creating a new list of a link

public class Link {

private int idata;
private long ddata;
link next;

public Link(int nidata,long nddata){
iData=nidata;
dData=nddata;
}
}

//A class for a FirstLastLink

public class FirstLastLink{
private LinkFirst;
private LinkLast;

public FirstLastLink(){

first=null;
last=null;
}
public boolean isEmpty(){
return(first && last==null);
}
public void insertFirst(int nidata,long nddata){ //method in inserting in the first link
Link newLink=new Link(nidata,nddata);
newLink.next=first;
first=newLink;
}
public void insertLast(int nidata,long nddata){ //method in inserting in the last link
Link newLink=new Link(nidata,nddata);
newLink.next=last;
last=newLink;
}

public Link deleteFirst(int nidata,long nddata){
Link temp=first;
first=first.next;
return temp;
}

public Link deleteLast(int nidata,long nddata){
Link temp2=last;
last=last.next;
return temp2;
}

public void displayList(){

System.out.println(The List(first--last):");
Link current=first;
Link current2=last;
while(current && current2 !=null){
current.displayList();
current.current.next;
current.current2.next;
}
System out.println(" ");
}
}

// Application of the FirstLastApp

public class FirstLastApp{
public static void main(String[]args){

FirstLastList theList=new FirstLastList();

theList.insertFirst(1, 1,000);
theList.insertFirst(2, 2,000);
theList.insertFirst(3, 3,000);

theList.insertLast(4, 4,000);
theList.insertLast(5, 5,000);
theList.insertLast(6, 6,000);


System.out.println(theList);
theList.deleteFirst();
theList.deleteLast();

System.out.println(theList);
}
}
d.) Reference:
[jeany acoja-for the implementation of code]

No comments:

Post a Comment