public class LinkHeap<T>
{
class Node<T>
{
T data;
Node<T> next;
Node(T data)
{
this.data = data;
this.next = null;
}
}

Node<T> font ;
Node<T> tail;

public LinkHeap()
{
this.font = null;
this.tail = null;
}

public boolean isEmpty()
{
return this.font==null && this.tail==null;
}
public void enQueue(T e)
{
if(this.isEmpty())
{
Node temp = new Node(e);
this.font = temp;
this.tail = this.font;
}
else
{
Node temp = new Node(e);
this.tail.next = temp;
this.tail = temp;
}
}

public Object deQueue()
{
if(this.isEmpty()) return null;
if(this.font==this.tail)
{
Node temp = this.font;
this.font = null;
this.tail = null;
return temp.data;
}
else
{
Node temp= this.font;
this.font = temp.next;
return temp.data;
}
}

public static void main(String[] args)
{
LinkHeap<Integer> mLinkHeap = new LinkHeap<Integer>();
for(int i=0;i<10;i++)
mLinkHeap.enQueue(new Integer(i+1));
while(mLinkHeap.isEmpty()==false)
{
System.out.print(mLinkHeap.deQueue()+"\t");
}
}
}