博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于位图、位向量的快速排序
阅读量:3563 次
发布时间:2019-05-20

本文共 1306 字,大约阅读时间需要 4 分钟。

需求:

1.需要就N位数字进行排序(N>5)

2.N位数是一个稠密的数字集合

3.集合中没有重复的元素(数字)

限制:

1.尽量减少内存使用

2.要求算法时间要短

 

先写一个工具类,生成稠密集合

import java.util.Date;import java.util.HashSet;import java.util.Random;import java.util.Set;public class InitArray{	public static Integer[] getArray(int nums)	{		int count=0;		Random random = new Random(new Date().getTime());		Set
set = new HashSet
(); for(;count
 

排序实现

import java.util.Date;public class BitMapSort{	//N 数字数量级	public static int NUMS=1000;	/**	* Logger for this class	*/	private static final Log logger = LogFactory.getLog(BitMapSort.class);	@SuppressWarnings("deprecation")	public static Integer[] sort(Integer array[])	{				byte[] loop =new byte[NUMS];				//置0 java默认为0//		for(int i=0;i
 

测试:

import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;public class Main{	/**	* Logger for this class	*/	private static final Log logger = LogFactory.getLog(Main.class);		private static int NUMS=BitMapSort.NUMS;	/**	 * main。  	 * 

详细说明:

*
* 无。 * @param args */ public static void main(String[] args) { logger.info("--------------生存"+NUMS+"以内的稠密数组--------------"); Integer array[] = InitArray.getArray(NUMS); logger.info("--------------生成完毕--------------"); Integer arr1[] = BitMapSort.sort(array); }}
 

 

说明:这个排序的速度很快,但是适合稠密的数据集合,不然会浪费很多内存。

转载地址:http://nthrj.baihongyu.com/

你可能感兴趣的文章
淘宝网站的架构演进
查看>>
设置zookeeper开机自启动流程
查看>>
CentOS安装mysql5.7的教详细流程
查看>>
项目整合微信扫码登录功能
查看>>
分布式文件系统FastDfs的搭建
查看>>
Springboot项目利用Java客户端调用FastDFS
查看>>
全文检索工具elasticsearch的安装和简单介绍
查看>>
利用Kibana学习全文检索工具elasticsearch
查看>>
SpringBoot在Test测试类或自定义类中通过@Autowired注入为null
查看>>
使用docker搭建YAPI服务
查看>>
西南科技大学OJ题 邻接表到邻接矩阵1056
查看>>
西南科技大学OJ题 有向图的出度计算1057
查看>>
西南科技大学OJ题 有向图的最大出度计算1059
查看>>
西南科技大学OJ题 带权有向图计算1063
查看>>
oracle主键自增触发器编写
查看>>
String与StringBuilder与StringBuffer三者的差别
查看>>
各种IO流之间的关系和区别
查看>>
SSM如何实现上传单图片
查看>>
SSM环境下java如何实现语音识别(百度语音识别版)
查看>>
ajax方法参数的用法和他的含义
查看>>