`
knight_black_bob
  • 浏览: 825824 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Queue 队列

 
阅读更多

 

 

 

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);
	}
 
}

 



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

  • 大小: 1.1 KB
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics