All pastes #772958 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-14 04:39 UTC
rendered paste body
   import java.util.Scanner;
   import java.io.*;
   import javax.swing.JOptionPane;
	
    public class DoubleLinked
   {
       public static void main(String[] args) throws FileNotFoundException
      {
			DLNode head=new DLNode();
			insert(head,"A");
			insert(head,"B");
			insert(head,"C");
			insert(head,"D");
			print(head);
			remove(head, 3);
			print(head);
	   }
   	
   	public static void print(DLNode head)
   	{
   		System.out.print("[");
    	while(head.getNext()!=null)
			head=head.getNext();
		while(head!=null)
		{
			System.out.print(head.getValue());
				if(head.getPrev()!=null)
					System.out.print(", ");
            head = head.getPrev();			
		}    
		  
		  
		  /* while(head != null)
         {	
				System.out.print(head.getValue());
				if(head.getNext()!=null)
					System.out.print(", ");
            head = head.getNext();
		   }*/
         System.out.println("]");
   	}

       public static void insert(DLNode t, Object obj)
      {
         if(t==null)
            {	
            	t = new DLNode(obj, null, null);
         	}
         else if(t.getNext()==null)
         {	
				System.out.print("FME2 "+obj);
         	t.setNext(new DLNode(obj,t,null));
			}
         else
         {
				System.out.print("FME3 "+obj);
            DLNode cool=new DLNode(obj,t,t.getNext());
    			t.getNext().setPrev(cool);	        
				t.setNext(cool);
         }
      }
   	
       public static void remove(DLNode t, int n)
      {
			DLNode p=t;
			while(p.getNext()!=null)
				p=p.getNext();
         for(int k=0;k<n-1;k++)
				p=p.getPrev();
         p.getPrev().setNext(p.getNext());
         p.getNext().setPrev(p.getPrev());
         
      }
   	
   }