我想通过Eclipse制作LinkedList
但我不知道如何制作LinkedList。
首先,我想与int的数据和参考进行比较。
但是,我不知道如何比较。

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");
         }
     }

}


而且,我完成了编程。但是,其结果为“ List.DoubleLinkedList@8c1dd9”

最佳答案

检查我的答案here的基础知识。列表中的元素必须实现Comparable,更多信息here

07-28 03:15
查看更多