一、使用双端链表实现队列代码如下:
import android.util.Log;
/**
* Created by Xi on 2017/8/1.
* 使用链表实现队列的队列
*/
public class QueueLink {
private LinkListQueue theList;
public QueueLink(){
theList=new LinkListQueue();
}
public boolean isEmpty(){
return theList.isEmpty();
}
public void insert(double dd){
theList.insertLast(dd);
}
public double remove(){
return theList.deleteFirst();
}
public void displayQueue(){
Log.v("QueueLink","QueueLink (front-->rear):");
theList.displayList();
}
}
二、主函数调用如下
/**
* 用双端链表实现队列
*/
public void link_queue(){
QueueLink theQueue=new QueueLink();
theQueue.insert(20);
theQueue.insert(30);
theQueue.displayQueue();
theQueue.insert(40);
theQueue.insert(50);
theQueue.displayQueue();
theQueue.remove();
theQueue.remove();
theQueue.displayQueue();
}
打印日志如下:
08-15 10:07:49.533 16378-16378/com.tool.wpn.quicksort V/QueueLink: QueueLink (front-->rear):
08-15 10:07:49.533 16378-16378/com.tool.wpn.quicksort I/LinkListQueue: List (first-->last):
08-15 10:07:49.534 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 20.0
08-15 10:07:49.534 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 30.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort V/QueueLink: QueueLink (front-->rear):
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkListQueue: List (first-->last):
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 20.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 30.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 40.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 50.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort V/QueueLink: QueueLink (front-->rear):
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkListQueue: List (first-->last):
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 40.0
08-15 10:07:49.535 16378-16378/com.tool.wpn.quicksort I/LinkFirstLast: 50.0
源码下载地址:点击打开链接