K12教育赛事综合服务平台
聚乐之家官方网站
下载聚乐之家官方App
专注青少年竞赛题库网站
现有商品类Commodity定义如下:
Commodity
class Commodity { int stock; // 库存数量 double price; // 商品售价 long shelfTime; // 上架时间戳,值越小代表上架越早 }
排序规则为:1. 优先按库存数量从高到低排序;2. 库存相同时,按商品售价从低到高排序;3. 前两项均相同时,按上架时间从早到晚排序。
Comparator<Commodity> cmp = (a, b) -> { if (a.price != b.price) return (int)(a.price - b.price); if (a.stock != b.stock) return b.stock - a.stock; return a.shelfTime - b.shelfTime; };```
Comparator<Commodity> cmp = (a, b) -> { if (a.stock != b.stock) return b.stock - a.stock; if (a.price != b.price) return (int)(a.price - b.price); return a.shelfTime - b.shelfTime; };```
Comparator<Commodity> cmp = (a, b) -> { if (a.shelfTime != b.shelfTime) return a.shelfTime - b.shelfTime; if (a.price != b.price) return (int)(a.price - b.price); return b.stock - a.stock; };```
Comparator<Commodity> cmp = (a, b) -> { if (a.stock != b.stock) return a.stock - b.stock; if (a.price != b.price) return (int)(b.price - a.price); return b.shelfTime - a.shelfTime; };```