PriorityQueue ,ArrayList , 数组排序
来源:互联网 发布:光棍儿 知乎 编辑:程序博客网 时间:2024/06/05 10:43
static class E implements Comparable<E>{ int x ; int y ; int state ; int money ; public E(int x , int y , int state , int money){ this.x = x ; this.y = y ; this.state = state ; this.money = money ; } @Override public int compareTo(E o) { return money - o.money ; } } PriorityQueue<E> q = new PriorityQueue<E>() ; q.add(new E(1, 0, 0, 1)) ; q.add(new E(2, 0, 0, 3)) ; q.add(new E(3, 0, 0, 2)) ; q.add(new E(4, 0, 0, 5)) ; q.add(new E(5, 0, 0, 9)) ; while(! q.isEmpty()){ System.out.println(q.poll().money) ; }输出结果:12359ArrayList<E> q = new ArrayList<E>() ; q.add(new E(1, 0, 0, 1)) ; q.add(new E(2, 0, 0, 3)) ; q.add(new E(3, 0, 0, 2)) ; q.add(new E(4, 0, 0, 5)) ; q.add(new E(5, 0, 0, 9)) ; Collections.sort(q) ; for(E e : q){ System.out.println(e.money) ; }输出结果:12359 E[] q = new E[100] ; q[0] = new E(1, 0, 0, 1) ; q[1] = new E(2, 0, 0, 3) ; q[2] = new E(3, 0, 0, 2) ; q[3] = new E(4, 0, 0, 5) ; q[4] = new E(5, 0, 0, 9) ; Arrays.sort(q , 0 , 5) ; for(int i = 0 ; i < 5 ; i++){ System.out.println(q[i].money) ; } 输出结果:12359 static class E{ int x ; int y ; int state ; int money ; public E(int x , int y , int state , int money){ this.x = x ; this.y = y ; this.state = state ; this.money = money ; } } ArrayList<E> q = new ArrayList<E>() ; q.add(new E(1, 0, 0, 1)) ; q.add(new E(2, 0, 0, 3)) ; q.add(new E(3, 0, 0, 2)) ; q.add(new E(4, 0, 0, 5)) ; q.add(new E(5, 0, 0, 9)) ; Collections.sort(q , new Comparator<E>() { @Override public int compare(E a , E b) { return a.money - b.money ; } } ) ; for(E e : q){ System.out.println(e.money) ; }输出结果:12359 E[] q = new E[100] ; q[0] = new E(1, 0, 0, 1) ; q[1] = new E(2, 0, 0, 3) ; q[2] = new E(3, 0, 0, 2) ; q[3] = new E(4, 0, 0, 5) ; q[4] = new E(5, 0, 0, 9) ; Arrays.sort(q, 0, 5, new Comparator<E>() { @Override public int compare(E a, E b) { return a.money - b.money ; } }) ; for(int i = 0 ; i < 5 ; i++){ System.out.println(q[i].money) ; }输出结果:12359 PriorityQueue<E> q = new PriorityQueue<E>(1 , new Comparator<E>() { @Override public int compare(E a , E b) { return a.money - b.money ; } }) ; q.add(new E(1, 0, 0, 1)) ; q.add(new E(2, 0, 0, 3)) ; q.add(new E(3, 0, 0, 2)) ; q.add(new E(4, 0, 0, 5)) ; q.add(new E(5, 0, 0, 9)) ; while(! q.isEmpty()){ System.out.println(q.poll().money) ; }输出结果:12359
0 0
- PriorityQueue ,ArrayList , 数组排序
- ArrayList,LinkedList,Stack,Queue,PriorityQueue 基本概念
- 用ArrayList对数组进行排序
- C#自定义对象排序(数组/ArrayList)
- PriorityQueue-数组(二叉堆)
- JAVA PriorityQueue实现定制排序
- Java中PriorityQueue的排序
- Java中PriorityQueue的排序,堆排序
- Java中PriorityQueue的排序,堆排序
- PriorityQueue
- PriorityQueue
- priorityqueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- Ogre播放动画
- 怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32
- 日经社説 20150727 ガス田合意の原点に回帰を
- PHP根据经纬度计算两点间实际距离
- Android Service的简介(自用)
- PriorityQueue ,ArrayList , 数组排序
- java多线程-专题-聊聊并发(六)ConcurrentLinkedQueue的实现原理分析
- java多线程设计模式--Balking不需要就算了
- UVALive 6912
- android-percent-support-extend根据百分比高效自动适配页面库。
- 【数据结构|剑指Offer】单向链表的各项操作实现
- jquery 深入学习笔记之一 (事件绑定)
- CodeForces 363C - Fixing Typos
- Mac 程序员必备软件