chuck@umiami.ir.miami.edu (Chuck Urwiler) (01/11/91)
I'm implementing a binary tree structure in a small program that I am writing in THINK C 4.0.2. Some questions: 1) What do I have to do (specifically) to keep my data structure intact? I have to do something with creating a handle, moving it to a high location in the heap, then locking it, correct? Someone with experience with this, please e-mail me specifics. I'm no genius when it comes to pointers yet. 2) I'm trying to use variable parameters in a function that will add nodes to the tree. I have several trees in this program, so it needs to be variable (I can't work with a globally defined variable) so that I can use this function all around. Has anyone else tried this? I'm having quite a bit of difficulty getting it to work. Here's some code: #define NILP 0L struct duration { int data; struct duration *lchild,*rchild; int quant;}; struct duration *dur,*top; main() { dur=NILP; menu(); } menu() {... case '1':printf("\nenter value to insert into tree:"); scanf("%d",&newnum); insert(dur,&dur,newnum); ... } insert(node,add,ndata) int ndata,*add; struct duration *node; { struct duration *temp; if (node==NILP) { temp=malloc(sizeof(struct duration)); if (temp!=0) { temp->lchild=NILP; temp->rchild=NILP; temp->data=ndata; *add = temp; } else puts("Can't allocate more space."); } else if (ndata < node->data) insert(node->lchild,&(node->lchild),ndata); else insert(node->rchild,&(node->rchild),ndata); } I can run this bit of code successfully on the VAX here (where I've been developing, for lack of access to a Mac), but when I moved it over to the Mac, it gives me "illegal operation" on the line *add=temp; It doesn't seem to like the dereferencing. Any help would be greatly appreciated. Please e-mail replies only. -- Chuck Urwiler University of Miami Music Engineering Voice & Keys =========================================================================== chuck@umiami -or @umiamivm (Bitnet) |"Sometimes, the one thing that you're chuck@umiami.ir.miami.edu (Internet) | looking for, it's the last thing on chuck@miavax.ir.miami.edu (Internet) | your mind" -Robbie Nevil pannet!curwiler@uunet.uu.net (PAN) | =========================================================================== Disclaimer: I only work and learn at this University. I don't speak for it!