| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 686 人关注过本帖
标题:比较复杂的数该怎么排序?
取消只看楼主 加入收藏
zhangenter
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:390
专家分:0
注 册:2006-6-5
收藏
 问题点数:0 回复次数:2 
比较复杂的数该怎么排序?

从键盘输入有正负号,有小数点的10个数字(数字位数可能很长,一个字或一个双字存储不下),对这十个数进行排序后输出,不知道谁有好点的方法.有没有代码没关系,关键是先有个算法分析,大家帮帮忙,谢谢了

搜索更多相关主题的帖子: 键盘 小数点 
2006-07-06 16:45
zhangenter
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:390
专家分:0
注 册:2006-6-5
收藏
得分:0 
c和汇编我都不懂,一个星期都没学到,你说的怎么导入我一点都不懂,不过还是谢谢你了

OldHandle = findobj( \'Name\', \'悲伤\' ) ;if ~isempty(OldHandle),delete(OldHandle) ;end for Time = \'现在\':\'每一天\':\'永远\',set( gco, \'心情\', \'快乐\');end % 这段代码为你天天快乐而存在
2006-07-06 23:34
zhangenter
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:390
专家分:0
注 册:2006-6-5
收藏
得分:0 

  汇编指令我知道的不多,连子程序都不知道怎么调用,下面是我编的,一路jmp下去
  程序非常乱,我说下基本思想,给10个数字每个预留20位,输入的时候空格作为两数分隔,回车作为输入结束,定义一个存单纯存储数字的数组number,定义一个存储数字位数的数组numlenth(不包括负号和小数点),定义处理负号先定义个10个元素的值为1的数组cmpzero,输入负号则把1改为0,对于小数点的处理,数组pointn记录下小数点之前数字位数,对没小数点的数字的pointn的值即是numlenth值,直接把numlenth值复制上去.排序是用冒泡法,比较大小时,先比负号数组,异号则跳出(大于互换,小于不换),同为负号的话用变量ccnum的值来记下,同正则比较pointn的值,即小数点之前数字位数的比较,数字位数不等则跳出,位数相等则逐位比较,若仍相等则比较小数位之后的数.数据输出时候读取排序模式的变量值,由于数组比较玩保存为升序了,如果选择的降序只要对数组从后往前输出.现在想想排序的时候数字互换太麻烦了,应该拿个指针来代替数字进行互换的.
data segment
number db 200 dup(?)
numlenth dw 10 dup(?)
ccnum db ?
pointn dw 10 dup(0)
cmpzero dw 10 dup(1)
select db 1
count1 dw ?
count2 dw ?
count3 dw ?
count4 dw ?
exit db 0dh,0ah,'please any key to exit','$'
input db 'please input the numbers:(dapart them with keyboard "space" and end with keyboad "enter")',0dh,0ah,'$'
choose db 0dh,0ah,'please choose sort style',0dh,0ah,'1 ascend',0dh,0ah,'2 descend',0dh,0ah,'$'
output db 0dh,0ah,'the sorted numbers are:',0dh,0ah,'$'
data ends

code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
sub si,si
sub bx,bx
sub di,di
sub cx,cx
mov count1,0
mov count2,0
mov ah,09h
lea dx,input
int 21h
sub dx,dx
inputdata:mov ah,01h
int 21h
cmp al,20h
jz nextdata
cmp al,0dh
jz endinput
cmp al,2eh
jnz numsign
mov bx,count1
mov pointn[di],bx
jmp inputdata
numsign: cmp al,2dh
jnz savedata
mov cmpzero[di],0
jmp inputdata
savedata:inc count1
mov number[si],al
inc si
jmp inputdata
nextdata: cmp pointn[di],0
jnz savenum
mov dx,count1
mov pointn[di],dx
savenum:mov dx,count1
mov numlenth[di],dx
add count2,20
mov si,count2
cmp count2,200
jz sortdata
mov count1,0
add di,2
jmp inputdata
endinput:cmp pointn[di],0
jnz nopoint
mov dx,count1
mov pointn[di],dx
nopoint: mov dx,count1
mov numlenth[di],dx
sortdata: add di,2
mov count1,0
selectstyle:
mov ah,09h
lea dx,choose
int 21h
mov ah,01h
int 21h
cmp al,49
jz selected
cmp al,50
jz selected
jmp selectstyle
selected:
mov select,al

mov count1,di
mov count4,di
mov count3,0
sub si,si
sub di,di

nextloop:
sub bx,bx
sub cx,cx
mov ccnum,0
mov dx,0
mov count2,0
mov ax,cmpzero[si]
cmp ax,cmpzero[si+2]
jna eeee
jmp change
eeee:
jnb dddd
jmp over2
dddd:
cmp ax,0
jnz gggg
mov ccnum,1
gggg:
mov ax,pointn[si]
cmp ax,pointn[si+2]
jna ffff
jmp change
ffff:
jnb cmpap
jmp over
cmpap:

mov ch,number[bx+di]
mov cl,number[bx+di+20]
cmp ch,cl

ja change


jb over

inc bx
cmp bx,ax
jnz cmpap

mov cx,numlenth[si]
cmp cx,ax
jnz aaaa
jmp over
aaaa:
mov dx,numlenth[si+2]
cmp dx,ax
jz change
cmpbp:mov ah,number[di+bx]
mov al,number[di+bx+20]
cmp ah,al
ja change
jb over
inc bx
cmp bx,cx
jz over
cmp bx,dx
jz change
jmp cmpbp
change:sub ax,ax
sub bx,bx
sub cx,cx
notchange:cmp ccnum,1
jz over2
mov ax,cmpzero[si]
xchg ax,cmpzero[si+2]
mov cmpzero[si],ax
mov ax,pointn[si]
xchg ax,pointn[si+2]
mov pointn[si],ax
mov ax,numlenth[si]
xchg ax,numlenth[si+2]
mov numlenth[si],ax
changenum:

mov al,number[di+bx]
xchg al,number[di+bx+20]
mov number[di+bx],al


inc bx
cmp bx,20
jnz changenum

over:cmp ccnum,1
jnz over2
mov ccnum,0
jmp change

over2:

add si,2
add di,20
cmp si,count1
jz bbbb
jmp nextloop
bbbb:
sub count1,2
mov count3,0

sub si,si
sub di,di
cmp count1,2
jz cccc
jmp nextloop
cccc:

cmp select,50
jz descend
mov ah,09h
lea dx,output
int 21h
sub si,si
sub bx,bx
sub cx,cx
mov count2,0
sub dx,dx
outputnext:mov cx,pointn[si]
sub di,di
add di,count2
add cx,count2
sub cmpzero[si],0
jnz outputdata
mov dl,2dh
mov ah,02h
int 21h
outputdata:mov dl,number[di]
mov ah,02h
int 21h
inc di
cmp di,cx
jnz outputdata
sub cx,count2
cmp cx,numlenth[si]
jz outputspace
mov dl,2eh
mov ah,02h
int 21h
mov cx,numlenth[si]
add cx,count2
jmp outputdata

outputspace:
add si,2
cmp si,count4
jnz hhhh
jmp exitall
hhhh:
mov dl,20h
mov ah,02h
int 21h
add count2,20
jmp outputnext
jmp exitall

descend:
mov ah,09h
lea dx,output
int 21h
sub si,si
sub bx,bx
sub cx,cx
sub dx,dx
mov ax,count4
mov di,20
mul di
mov count2,ax
mov si,count4
outputnext2:mov cx,pointn[si]
sub di,di
add di,count2
add cx,count2
sub cmpzero[si],0
jnz outputdata
mov dl,2dh
mov ah,02h
int 21h
outputdata2:mov dl,number[di]
mov ah,02h
int 21h
inc di
cmp di,cx
jnz outputdata2
sub cx,count2
cmp cx,numlenth[si]
jz outputspace2
mov dl,2eh
mov ah,02h
int 21h
mov cx,numlenth[si]
add cx,count2
jmp outputdata2

outputspace2:
sub si,2
cmp si,count4
jz exitall
mov dl,20h
mov ah,02h
int 21h
sub count2,20
jmp outputnext2

exitall:
mov ah,09h
lea dx,exit
int 21h
mov ah,01h
int 21h
mov ah,4ch
int 21h
code ends
end start
运行的时候还有问题,现在这段只能实现输满10个数字的升序排序,降序有乱码,不输满10位回车也有乱码,问题还在找,哪位高手发现错在哪的话也请指出.


OldHandle = findobj( \'Name\', \'悲伤\' ) ;if ~isempty(OldHandle),delete(OldHandle) ;end for Time = \'现在\':\'每一天\':\'永远\',set( gco, \'心情\', \'快乐\');end % 这段代码为你天天快乐而存在
2006-07-07 23:50
快速回复:比较复杂的数该怎么排序?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021950 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved