Queue 队列

 

 

 

package javacore;
/**
 * @author baoyou  E-mail:[email protected]
 * @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);
	}
 
}

 



 

 

 

你可能感兴趣的:(Queue 队列)