首页 > 其他 > 详细

Queue 队列

时间:2015-09-11 02:10:05      阅读:266      评论:0      收藏:0      [点我收藏+]

?

?

?

package javacore;
/**
 * @author baoyou  E-mail:curiousby@163.com
 * @version 创建时间:2015年9月10日 下午2:23:04 
 * des:
 */
public class Queue {
  
	class Node {
        int data;
		Node next;   

        public Node(int data) {
            this.data = data;
        }
    }
	
	transient  Node head;
	transient  Node current;
     
    public void push(int data) {
        if (head == null) {
            head = new Node(data);
            current = head;
        } else {
            Node node = new Node(data);
            current.next = node; 
            current = current.next;  
        }
    }

    public Node pop() {
        if (head == null) {
            return null;
        }

        Node node = head; 
        head = head.next;   
        return node;
    }

    public static void main(String[] args) {
		Queue stack = new Queue ();
		stack .push(1);
		stack .push(2);
		stack .push(3);
		System.out.println(stack.pop().data);
		System.out.println(stack.pop().data);
		System.out.println(stack.pop().data);
	}
 
}

?


bubuko.com,布布扣
?

?

?

Queue 队列

原文:http://knight-black-bob.iteye.com/blog/2242393

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!