计数排序

2021-03-14 07:37

阅读:510

标签:dex   code   cache   imp   rgs   next   exti   main   ati   

import java.util.Arrays; import java.util.Random; public class CountSort { static class Item { int index; int num; } private static void sort(Item[] items, int bound) { int n = items.length; int[] count = new int[bound]; int[] sum = new int[bound]; Item[] cache = Arrays.copyOf(items, n); for (int i = 0; i = 0; -- i) { items[-- sum[cache[i].num]] = cache[i]; } } public static void main(String[] args) { int n = 10; Random random = new Random(); Item[] items = new Item[n]; for (int i = 0; i { System.out.println(item.index + "->" + item.num); }); sort(items, 5); System.out.println("排序后"); Arrays.stream(items).forEach(item -> { System.out.println(item.index + "->" + item.num); }); } }

计数排序

标签:dex   code   cache   imp   rgs   next   exti   main   ati   

原文地址:https://blog.51cto.com/tianyiya/2553857


评论


亲,登录后才可以留言!