序号之间的比较 [英] compare between sequential number

查看:86
本文介绍了序号之间的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个顺序排列的员工号码

喜欢

1

100

101

102

103







2

$

201





和我进行二分查找在他们身上

但是我遇到了一个问题,即连续数字中的
考虑2> 103

但是当在二元搜索中比较这两个数字时考虑103> 2

因为103中的数字位数大于2

中的位数是否有一种方法可以比较序号而不会遇到这个问题

请帮助

I have a staff numbers arranged sequentially
like
1
100
101
102
103
.
.
.
2
200
201
.
.
and i make a binary search on them
but i faced a problem that
in sequential numbers consider 2>103
but when comparing between these two number in binary serach consider 103>2
because the number of digits in 103 bigger than the number of digits in 2
is there a way to compare between sequential number without facing this problem
please help

推荐答案

没有。这没有道理。 2≯201,103> 2.问题中显示的序列不是顺序,如果您的意思是订购我的数值。



如果您需要其他订单,请说明订购比较规则,或者自己动手。



-SA
No. It makes no sense. 2 ≯ 201, 103 > 2. Your sequence shown in the question is not "sequential", if you mean ordering my its numeric value.

If you need some other order, please explain the ordering comparison rule, or do it by yourself.

—SA


不要使用用于存储数字,日期等的字符串
Don''t use strings to store numbers, dates, etc.


如果必须将这些字符串排序为字符串,并且知道字符串的最大长度,则将它们填充为零。即如果最大长度是10位,则将1改为0000000001。然后订购就可以了。

但是,如果你知道它们总是只包含数字,你可能希望将它们存储为整数,如PIEBALDconsult建议的那样。

此致,

Ian。
If you have to sort these as a string, and you know the maximum length of the string, then zero-pad them. i.e. if the maximum length is 10 digits, then change "1" to "0000000001". Then the ordering will work.
Howeever, if you know they are always going to consist only of digits, you probably want to store them as integers, as PIEBALDconsult suggested.
Regards,
Ian.


这篇关于序号之间的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆