优先级队列
2015-10-15 00:00
525 查看
package com.bjwilly.test; import java.util.PriorityQueue; public class PriorityQueueTest extends PriorityQueue<PriorityQueueTest.TodoItem>{ static class TodoItem implements Comparable<TodoItem>{ private char primary; private int secondary; private String item; public TodoItem(String td, char pri, int sec){ primary = pri; secondary = sec; item = td; } @Override public int compareTo(TodoItemarg) { if (primary > arg.primary) return + 1 ; if (primary == arg.primary) if (secondary > arg.secondary) return + 1 ; else if (secondary == arg.secondary) return 0 ; return - 1 ; } public String toString(){ return Character.toString(primary)+ secondary + ": " + item; } } public void add(String td, char pri, int sec){ super .add( new TodoItem(td,pri,sec)); } public static void main(String[] args) { PriorityQueueTesttoDoList = new PriorityQueueTest(); toDoList.add( "Empty trash" , 'C' , 4 ); toDoList.add( "Feed dog" , 'A' , 2 ); toDoList.add( "Feed bird" , 'B' , 7 ); toDoList.add( "Mow lawn" , 'C' , 3 ); toDoList.add( "Water lawn" , 'A' , 1 ); toDoList.add( "Feed cat" , 'B' , 1 ); while (!toDoList.isEmpty()) System.out.println(toDoList.remove()); } } |
A1: Water lawn A2: Feed dog B1: Feed cat B7: Feed bird C3: Mow lawn C4: Empty trash
http://www.bjwilly.com/archives/202.html
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统