- public class IntDLLNode {
- public int info;
- public IntDLLNode next,prev;
- public IntDLLNode(int e1){
- this(e1,null,null);
- }
- public IntDLLNode(int e1,IntDLLNode n,IntDLLNode p){
- this.info=e1;
- this.next=n;
- this.prev=p;
- }
- }
复制代码
- public class IntDLList {
- private IntDLLNode head,tail;
- public IntDLList(){
- head=tail=null;
- }
- public boolean isEmpty(){
- return head==null;
- }
- public void addToTail(int e1){
- if(!isEmpty()){
- tail=new IntDLLNode(e1,null,tail);
- tail.prev.next=tail;
- }
- else{
- head=tail=new IntDLLNode(e1);
- }
- }
- public int removeFromTail(){
- int e1=tail.info;
- if(head==tail){
- head=tail=null;
- }
- else{
- tail=tail.prev;
- tail.next=null;
- }
- return e1;
- }
- }
复制代码
|