c++ 基数排序算法_基数排序算法– C / C ++实现的基础

c++ 基数排序算法

Radix Sort Algorithm is a unique sorting algorithm that works on the basic principle of numbers being an ensemble of digits. Radix Sort works only on integer values since integers have only a single mathematical component, digits.

基数排序算法是一种独特的排序算法,它根据数字是一组数字的基本原理进行工作。 “基数排序”仅适用于整数值,因为整数只有一个数学成分,即数字。

In this sorting algorithm, the numbers are initially arranged according to their least significant digit, moving onto their most significant digit, while maintaining the previous order.

在这种排序算法中,数字最初是根据其最低有效位排列的,然后移至其最高有效位,同时保持先前的顺序。



基数排序算法如何工作? (How Does the Radix Sort Algorithm Work?)

Let us quickly jump to the details of the algorithm, with an example running side by side.

让我们快速并肩并举一个例子,快速了解算法的细节。

Radix Sort Input Array
Input Array
输入数组

步骤1:找出最大元素 (Step 1: Finding the maximum element)

As we previously mentioned, the algorithm arranges numbers using the least significant digit to the most significant digit, therefore we need to know the range of these iterations. For this purpose, we need to find the maximum element.

如前所述,该算法使用最低有效位到最高有效位来排列数字,因此我们需要知道这些迭代的范围。 为此,我们需要找到最大元素。

Radix Sort Max Element
Maximum element in the array
数组中的最大元素

After finding the maximum number, we need to count its digits.

找到最大数量后,我们需要计算其位数。



步骤2:计算最大位数的位数 (Step 2: Count the number of digits of the maximum number)

We need to know the number of times we have to arrange the array, therefore there is a necessity to count the number of digits.

我们需要知道必须安排数组的次数,因此有必要计算数字的位数。

Radix Sort No Of Digits
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值