acid45
04-25-2003, 09:49 AM
I got it prety much. only the tree isn't sorted when reading from file and it only reads nodes to the right side of root and not to left...I fixed a bit of my code and I'm having trouble with this and need to be able to fill in the left side of the tree I don't kno wwhy it ****s up it seems liek it should work to me.
void readrest()
{
linkwork = linkhead;
while(linkwork->next != NULL)
{
work = root;
while(work != NULL && linkwork->bookkey < work->bookkey && work->bookkey > 0)
{
if(work == root)
{
if(work->left == NULL)
{
work->left = (struct node *) malloc(sizeof(struct node));
}
work = work->left;
root->left = work;
}
else
{
if(work->left == NULL)
{
work->left = (struct node *) malloc(sizeof(struct node));
}
parent = work;
work = work->left;
printf("%i\n",work->bookkey);
parent->left = work;
parent->right = NULL;
}
}
while(work != NULL && work->bookkey > 0 && linkwork->bookkey > work->bookkey)
{
if(work == root)
{
if(work->right == NULL)
{
work->right = (struct node *) malloc(sizeof(struct node));
}
work = work->right;
root->right = work;
}
else
{
if(work->right == NULL)
{
work->right = (struct node *) malloc(sizeof(struct node));
}
parent = work;
work = work->right;
printf("%i\n",work->bookkey);
parent->right = work;
parent->left = NULL;
}
}
if(work != root)
{
strcpy(work->bookauthor, linkwork->bookauthor);
work->bookkey = linkwork->bookkey;
work->bookpages = linkwork->bookpages;
strcpy(work->booktitle, linkwork->booktitle);
work->bookloaned.dd = linkwork->bookloaned.dd;
work->bookloaned.mm = linkwork->bookloaned.mm;
work->bookloaned.yyyy = linkwork->bookloaned.yyyy;
work->deleted = 0;
work->right = NULL;
work->left = NULL;
}
linkwork = linkwork->next;
}
}
If anyone could point me in the right direction. I figured out my last problem when soemone said struct linknode's next pointer pointed to a struct node which rang bells..."oh jesus "fudge" (tastes good :P) am I a moron or what??? linknode->next points to node...GAH"...I jsut need a mention of what's wrong. I miss small stupid SEVERE errors...IF I ever become a programmer I'll need to hire a personal debugger :P
void readrest()
{
linkwork = linkhead;
while(linkwork->next != NULL)
{
work = root;
while(work != NULL && linkwork->bookkey < work->bookkey && work->bookkey > 0)
{
if(work == root)
{
if(work->left == NULL)
{
work->left = (struct node *) malloc(sizeof(struct node));
}
work = work->left;
root->left = work;
}
else
{
if(work->left == NULL)
{
work->left = (struct node *) malloc(sizeof(struct node));
}
parent = work;
work = work->left;
printf("%i\n",work->bookkey);
parent->left = work;
parent->right = NULL;
}
}
while(work != NULL && work->bookkey > 0 && linkwork->bookkey > work->bookkey)
{
if(work == root)
{
if(work->right == NULL)
{
work->right = (struct node *) malloc(sizeof(struct node));
}
work = work->right;
root->right = work;
}
else
{
if(work->right == NULL)
{
work->right = (struct node *) malloc(sizeof(struct node));
}
parent = work;
work = work->right;
printf("%i\n",work->bookkey);
parent->right = work;
parent->left = NULL;
}
}
if(work != root)
{
strcpy(work->bookauthor, linkwork->bookauthor);
work->bookkey = linkwork->bookkey;
work->bookpages = linkwork->bookpages;
strcpy(work->booktitle, linkwork->booktitle);
work->bookloaned.dd = linkwork->bookloaned.dd;
work->bookloaned.mm = linkwork->bookloaned.mm;
work->bookloaned.yyyy = linkwork->bookloaned.yyyy;
work->deleted = 0;
work->right = NULL;
work->left = NULL;
}
linkwork = linkwork->next;
}
}
If anyone could point me in the right direction. I figured out my last problem when soemone said struct linknode's next pointer pointed to a struct node which rang bells..."oh jesus "fudge" (tastes good :P) am I a moron or what??? linknode->next points to node...GAH"...I jsut need a mention of what's wrong. I miss small stupid SEVERE errors...IF I ever become a programmer I'll need to hire a personal debugger :P