user1421768
user1421768

Reputation:

Making Linked List

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'

Upvotes: 0

Views: 76

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76434

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

Upvotes: 1

Related Questions