这个汇编程序是利用数组和递归实现二叉树的建立与遍历,带注释的,下面是部分代码,与大家分享了
.model small
.stack 64
.data
Array db 32 dup(0,0,0)
MSG1 db 0ah,0dh,'$'
MSG2 db "Please input the root node of the binary: ",'$'
MSG3 db "'s leftchild is(no leftchild,press ENTER):",'$'
MSG4 db "'s rightchild is(no rightchild,press ENTER):",'$'
MSG5 db "Preorder is:",'$' ;先序结果
MSG6 db 0ah,0dh,"Inorder is:",'$' ;中序结果
MSG7 db 0ah,0dh,"Postorder is:",'$' ;后序结果
;主过程========================================================
.code
main proc far
mov ax,@data
mov ds,ax ;初始化段寄存器
lea si,Array ;将数组的首地址放进索引寄存器SI
sub cx,cx
mov ah,09h
lea dx,MSG2
int 21h ;提示输入根结点
mov ah,01h
int 21h
cmp al,0dh
je exit
call storage ;调用存储部分
call preorder ;先序遍历
lea dx,MSG6
call prepare
call inorder ;中序遍历
lea dx,MSG7
call prepare
call postorder ;后序遍历
exit:
mov ah,4ch
int 21h
main endp
1