java数据结构之双端链表

继上次写的链表,这次接着写,所谓双端链表,就是链表中保留着对最后一个链接点引用的链表

public class Node {
  private int data;
  private Node next;
  public Node(int value){
	this.data=value;
}
  public void display(){
	System.out.println(data+" ");
}
}
//结点
 
public class lianbiao {
	private Node first;
	private Node last;
public lianbiao(){
	first=null;
	last=null;
}

public Node deletefirst(){
	Node tmp=first;
	if(first.next==null){
		last=null;
	}
	first=tmp.next;
	return tmp;
}
public void display(){
	Node node=first;
	while(node!=null){
		node.display();
		node=node.next;
		
	}
}


	


public boolean isEmpty(){
	if(first==null){
		return true;
	}else{
		return false;
	}
}



public void insertfirst(int value){
	Node node=new Node(value);
	if(isEmpty()){
		last=node;
	}
	node.next=first;
	first=node;
}


public void insertlast(int value){
	Node node=new Node(value);
	if(isEmpty()){
		first=node;
	}else{
		last.next=node;
	}
	last=node;
}
}
//链表

 

你可能感兴趣的:(Java)