java队列的链表实现
2016-03-21 13:13
525 查看
java的队列实现
public class LinkQueue { Node head = null; Node tail = null; boolean isEmpty(){ if(head==null) return true; else return false; } void put(T data){ Node newNode = new Node(data); if(head==tail && head==null){ newNode.next = tail; tail = head = newNode; }else{ tail.next = newNode; tail = newNode; } } T pop(){ if(!isEmpty()){ Node popNode= head; head = head.next; return popNode.data; }else{ tail=head=null; return null; } } public static void main(String[] args) { LinkQueue linkQueue = new LinkQueue(); linkQueue.put(1); linkQueue.put(11); linkQueue.put(111); linkQueue.put(1111); linkQueue.put(11111); while(!linkQueue.isEmpty()){ System.out.println(linkQueue.pop()); } } } class Node{ E data; Node next = null; public Node() { } Node(E data){ this.data = data; } }
相关文章推荐
- struts2 上传文件相关
- 第二章 Java内存区域与内存溢出异常
- JAVA基础英语单词表(中)
- 利用spring AOP 和注解实现方法中查cache-我们到底能走多远系列(46)
- Java中的初始化
- java优化占用内存的方法(一)
- Java内存区域与内存溢出异常(二)
- 深入理解java垃圾回收机制
- 找到假币
- java比较器Comparable接口和Comaprator接口
- IT忍者神龟之Eclipse常用开发插件
- 关于Java中的继承和组合的一个错误使用的例子
- java写入文件
- java文件
- Spring通过@Value注解注入属性的几种方式
- Java的n++问题
- Java技术_Java千百问(0009)_java开发应该使用什么工具
- Spring Boot 定时任务的使用
- Maven 发布项目到Jetty服务器
- Maven 发布项目到Jetty服务器