0

I want to make LinkedList by Eclipse but i don't know how to make LinkedList. First of all, I want to compare with int's data and reference. but, i don't know how to compare.

package List;

public class DoubleLinkedList 
{
    CellDouble x;
    CellDouble head;//List's head
    public DoubleLinkedList()
    {
        //리스트의 헤더를 할당한다.
        head=new CellDouble(0);
        head.prev=head.next=head;
    }

    public void insertAfter(CellDouble p,int data)
    {
        CellDouble x=new CellDouble(data);
        x.prev=p;
        x.next=p.next;
        p.next.prev=x;
        p.next=x;


    }

    public void insertFirst(int data)
    {
        //List's next to insert
        insertAfter(head.next,data);
    }
    public void insertLast(int data)
    {
        //list's last's next to insert.
        insertAfter(head.prev,data);
    }
    public void removeCell(CellDouble p)
    {

        p.prev.next=p.next;
        p.next.prev=p.prev;
    }

    public Object removeFirst()
    {

        if(isEmpty())
        {
            return null;
        }
        CellDouble cell=head.next;
        removeCell(cell);
        return cell.data;
    }
    public Object removeLast()
    {
        // 요소가 없다면  null 반환
        if(isEmpty())
        {
            return null;
        }
        CellDouble cell=head.prev;
        removeCell(cell);
        return cell.data;       
    }
    public boolean isEmpty()
    {
        return head.next==head;
    }

     public void FindNumber(int data)
     {
         if(x==null)
         {
             insertFirst(data);
         }
         else if(x.data<data)
         {
             insertAfter(x,data);
         }
     }
     public void Findnumber(int data)
     {
         if(x.data==data)
         {
             removeCell(x);
         }
         else if(x.data!=data)
         {
             System.out.println("like this number is nothing");
         }
     }

}

And, I finished my programming. but, its outcome 'List.DoubleLinkedList@8c1dd9'

3
  • Do you checked this? docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html Commented May 28, 2012 at 13:17
  • this is just outputting the LinkedList that you have created , what exactly are you expecting as the output ? Commented May 28, 2012 at 13:18
  • As your code stands, it wouldn't compile since FindNumber is defined twice. Commented May 28, 2012 at 14:32

1 Answer 1

1

Check my answer here for the basics. The elements of your list must implement Comparable, read more here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.