Hi Everyone

I'm having problems passing pointers and getting desired results

I have a C++ & ASM program of a binary tree, I'm doing this for fun and to keep it whole, if one part works I can make another work, anyway

What I'm trying to do is

I have this function in C class

void tree::inOrder(NodePtr tPtr)
{

if ( tPtr != NULL ) {
inOrder( tPtr->left );
inOrderASM(tPtr->left );
cout<<tPtr->myKey<<" ";
inOrder( tPtr->right );
inOrderASM(tPtr->right );
}
}

this ASM procedure

inOrderASM proc , tPtr:PTR
LOCAL intBuffer[128]:BYTE

mov eax,tPtr
invoke wsprintf,ADDR intBuffer,ADDR printint, eax
invoke StdOut,ADDR intBuffer
ret
inOrderASM endp

Tree Traversal:
Inorder: 0 2 0 8466232 5 0 7 0 8466568 10 0 12 0 8466624 8466288

I'd like to know how to get
Inorder: 2 5 7 10 12

Preorder: 5 2 10 7 12
Postorder: 2 7 12 10 5
Posted on 2002-05-19 11:42:53 by andy981
I afraid, nobody understood this question. Please give some more hints:

- what is the algorithm used (binary tree - what task to solve)?
- where does the input come from?
- what is the main question of your post?

maybe a code snip could help further.
Posted on 2002-05-21 03:49:24 by beaster
The InOrderASM procedure simply prints out the value passed to it. In your C++ code you're passing the value tPtr -> left and tPtr -> right. To get the desired output you should just delete the InOrderAsm procedure calls.
Posted on 2002-05-21 08:06:24 by AmkG
Hi Everyone I added a a zip file of the program I made in C++
of a binary tree class, what I'm playing with is making the function as ASM procedures, and then I may just write a pure ASM tree program,

Anyway look for this function in tree.cpp

//prints tree out in an inorder list.

void tree::inOrder(NodePtr tPtr)
{
if ( tPtr != NULL ) {
inOrder( tPtr->left );
inOrderASM(tPtr); <- my asm procedure
inOrder( tPtr->right );

}


}


I got it now where it prints in ASM, but like to make the whole
procedure ASM, but it's tricky
But I did learn from this how use structs in ASM better

Thanks everyone, you might have fun with this , Oh yes
You need Visual C++, well that's what I use
And in settings, I have my cusom build
commands set
D:\masm32\Bin\ml.exe /c /Cx /coff $(InputPath)

This is for the ASM procedure

Write me if you need any instructions on getting ASM
running in Visual C

Thanls Andy
Posted on 2002-05-21 17:34:20 by andy981
class Node{

public:
Node * Left;
Node * Right;
int number;
Node(int n){
number = n;
Left = NULL;
Right = NULL;
}
~Node(){}
void PreOrder() const;
void PostOrder() const;
void InOrder() const;
};

void Node::PreOrder() const{
cout << number;
if(Left) Left->PreOder();
if(Right) Right->PreOrder();
}

void Node::PostOrder() const{
if(Left) Left->PostOder();
if(Right) Right->PostOrder();
cout << number;
}

void Node::InOrder() const{
if(Left) Left->InOder();
cout << number;
if(Right) Right->InOrder();
}
Posted on 2002-05-21 17:58:53 by bdjames