链表实现队列
Posted ssdut_yrp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链表实现队列相关的知识,希望对你有一定的参考价值。
public class Link
public long lData;
public Link next;//reference to next Link
public Link(long lData)
this.lData=lData;
public void displayLink()
System.out.print(""+lData+"");
public class FirstLastList
private Link first;
private Link last;
public FirstLastList()
first=null;
last=null;
public boolean isEmpty()
return (first==null);
public void insertLast(long dd)
Link newLink = new Link(dd);
if(isEmpty())
first=newLink;
else
last.next=newLink;
last=newLink;
public long deleteFirst()
long temp=first.lData;
if(first.next==null)
last = null;
first=first.next;
return temp;
public void displayList()
Link current =first;
while(current!=null)
current.displayLink();
current=current.next;
public class LinkQueue
private FirstLastList theList;
public LinkQueue()
theList =new FirstLastList();
public boolean isEmpty()
return (theList.isEmpty());
public void insert(long j)
theList.insertLast(j);
public long remove()
return theList.deleteFirst();
public void displayQueue()
theList.displayList();
public class LinkQueueApp
/**
* @param args
*/
public static void main(String[] args)
// TODO Auto-generated method stub
LinkQueue theQueue = new LinkQueue();
theQueue.insert(20);
theQueue.insert(40);
theQueue.displayQueue();
theQueue.remove();
theQueue.displayQueue();
以上是关于链表实现队列的主要内容,如果未能解决你的问题,请参考以下文章
算法漫游指北(第五篇):栈队列栈结构实现基于列表实现栈基于链表实现栈基于列表实现队列基于链表实现队列
算法漫游指北(第五篇):栈队列栈结构实现基于列表实现栈基于链表实现栈基于列表实现队列基于链表实现队列