中国开发网: 论坛: 程序员情感CBD: 贴子 607140
haitao
元器件编号,如C1,C2,...,C23,C24, R1,R2,...,R78,R88,...,R156,R157,正确的排序比较函数该怎么写呢?
元器件编号,如C1,C2,...,C23,C24, R1,R2,...,R78,R88,...,R156,R157,正确的排序比较函数该怎么写呢?
即C9是小于C12

用delphi写的了一个,感觉很冗长:

for i := 1 to length(bom1s[l].ref) do
Begin
if i>length(bom1s[r].ref) then
Begin
result:=1;
exit;
End;

if bom1s[l].ref[i] in ['0'..'9'] then
if bom1s[r].ref[i] in ['0'..'9'] then
Begin
a:=strtointdef(copy(bom1s[l].ref,i,100),cerr);
b:=strtointdef(copy(bom1s[r].ref,i,100),cerr);
if (a=cerr) or (b=cerr) then
Begin
result:=AnsiCompareText(bom1s[l].ref,bom1s[r].ref);
exit;
End;
if a>b then
result:=1
else if a<b then
result:=-1
else
result:=0;
exit;
End
else
Begin
result:=AnsiCompareText(bom1s[l].ref,bom1s[r].ref);
exit;
End
else
if bom1s[r].ref[i] in ['0'..'9'] then
Begin
result:=AnsiCompareText(bom1s[l].ref,bom1s[r].ref);
exit;
End
else
Begin
if bom1s[r].ref[i]=bom1s[l].ref[i] then
Continue;
if bom1s[r].ref[i]>bom1s[l].ref[i] then
result:=1
else
result:=-1;
exit;
End;
End;

if length(bom1s[l].ref)<length(bom1s[r].ref) then
result:=-1
else
result:=0;
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录