我想通过 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'