---
title: "数据结构队列的应用"
author: "wustrive_2008"
date: "2011-09-28T18:26:37Z"
tags: ["Java", "数据结构", "队列"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-09-28T18:31:38Z"
id: 1182665
url: "https://wustrive-2008.iteye.com/blog/1182665"
---

```
package com.guxia;

import java.util.*;

public class Test2 {
	public static void main(String[] args) {
		Queue<Integer> queue = new PriorityQueue<Integer>(10,
				new Comparator<Integer>(){
			public int compare(Integer i,Integer j) {
				// TODO Auto-generated method stub
				int result = i%2-j%2;
				if(result==0)
					result = i-j;
				return result;
			}
		});
		for(int i=0;i<10;i++){
			queue.offer(i);
		}
		for(int i=0;i<10;i++){
			System.out.println(queue.poll());
		}
	}
}
```

```
输出结果：0 2 4 6 8 1 3 5 7 9
```