sort-桶排序
void list_insert(list<int> &t,int num)
{
auto iter=t.begin();
for(;iter!=t.end();++iter)
{
if(num<=*iter)
break;
}
t.insert(iter,num);
}
void sort_bucket(vector<int> &v)
{
int bucket_num=6;
vector<list<int>> vlist=vector<list<int>>(bucket_num);
int mix=v[0];
int max=v[0];
for(int i=1;i<v.size();i++)
{
if(v[i]>max) max=v[i];
if(v[i]<mix) mix=v[i];
}
int space=(max-mix)/(bucket_num-1);
for(int i=0;i<v.size();i++)
{
int index=(v[i]-mix)/space;
list_insert(vlist[index],v[i]);
}
v.clear();
for(int i=0;i<vlist.size();i++)
{
for(auto iter=vlist[i].begin();iter!=vlist[i].end();++iter)
v.push_back(*iter);
}
}
sort-桶排序的更多相关文章
- sort(桶排序+hash)
题目链接:https://cn.vjudge.net/problem/HDU-1425 注意是多组输入 代码: #include<cstdio> #include<iostream& ...
- 计数排序和桶排序(Java实现)
目录 比较和非比较的区别 计数排序 计数排序适用数据范围 过程分析 桶排序 网络流传桶排序算法勘误 桶排序适用数据范围 过程分析 比较和非比较的区别 常见的快速排序.归并排序.堆排序.冒泡排序等属于比 ...
- [LeetCode] 桶排序的特殊解,例 Sort Color
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...
- Bucket Sort - leetcode [桶排序]
桶排序(Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将数组分到有限数量的桶里.每个桶再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序).桶排序是鸽巢排序 ...
- 计数排序与桶排序(bucket sort)
Bucket Sort is a sorting method that subdivides the given data into various buckets depending on cer ...
- 桶排序bucket sort
桶排序 (Bucket sort)或所谓的箱排序的原理是将数组分到有限数量的桶子里,然后对每个桶子再分别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序),最后将各个桶中的数据有序的 ...
- 451. Sort Characters By Frequency(桶排序)
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- 【算法】桶排序(Bucket Sort)(九)
桶排序(Bucket Sort) 桶排序是计数排序的升级版.它利用了函数的映射关系,高效与否的关键就在于这个映射函数的确定.桶排序 (Bucket sort)的工作的原理:假设输入数据服从均匀分布,将 ...
- 桶排序/基数排序(Radix Sort)
说基数排序之前,我们先说桶排序: 基本思想:是将阵列分到有限数量的桶子里.每个桶子再个别排序(有可能再使用别的排序算法或是以递回方式继续使用桶排序进行排序).桶排序是鸽巢排序的一种归纳结果.当要被排序 ...
- 排序:桶排序Bucket sort
补充说明三点 1,桶排序是稳定的 2,桶排序是常见排序里最快的一种,比快排还要快…大多数情况下 3,桶排序非常快,但是同时也非常耗空间,基本上是最耗空间的一种排序算法 无序数组有个要求,就是成员隶属于 ...
随机推荐
- deepin安装Python3.6和pip
1.安装python3.6 sudo apt-get install python3.6 2.修改软连接 sudo ln -s /usr/local/bin/python3.6 /usr/bin/py ...
- django图书管理系统实例
首页,其他页面全部继承首页的上半部分 点击发布图书页面 首页点击书名,跳转到图书信息界面,该界面可删除图书 项目结构 #views.py from django.shortcuts import re ...
- Python3 格式化字符串
Python3 格式化字符串 在Python 3.6之前,有两种将Python表达式嵌入到字符串文本中进行格式化的主要方法:%-formatting和str.format() 一.%-formatti ...
- Spring Boot(九):定时任务
Spring Boot(九):定时任务 一.pom包配置 pom包里面只需要引入springboot starter包即可 <dependencies> <dependency> ...
- 一次 Java 内存泄漏排查过程,涨姿势
人人都会犯错,但一些错误是如此的荒谬,我想不通怎么会有人犯这种错误.更没想到的是,这种事竟发生在了我们身上.当然,这种东西只有事后才能发现真相.接下来,我将讲述一系列最近在我们一个应用上犯过的这种错误 ...
- python3 独立环境 virtualenv & conda
python3 独立环境 virtualenv & conda virtualenv 创建独立python环境 virtualenv env_name -p /usr/bin/python3 ...
- opencv学习之路(6)、鼠标截图,滑动条播放视频
一.鼠标截图 #include<opencv2/opencv.hpp> #include<iostream> using namespace cv; using namespa ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
- topcoder srm 683 div1
problem1 link 肯定存在相邻两堆满足不会存在任何操作在这两堆之间进行.然后就成为一条链,那么只需要维护链的前缀和即可判断当前堆和前一堆之间需要多少次操作. problem2 link 对于 ...
- 如何卸载旧版本的dotnet core
How to remove the .NET Core Runtime and SDK https://docs.microsoft.com/en-us/dotnet/core/versions/re ...