Binary Tree
Binary Tree
- Subject: Binary Tree
- From: Nick <email@hidden>
- Date: Thu, 21 Mar 2002 19:09:23 +0700
Hello all.
I'm trying to make a binary tree which I encode and save to a file and
later decode and reuse. For some reason whenever I try to unarchive the
data for the tree I get an error saying that there was an unexpected end
of archive at 74 (the data is actually 501 bytes long).
The tree is made up of the NDScoreTree class which has as an instance
variable a node (of the HighScore class) called pRoot.
This is the encoding code for the NDScoreTree:
//********** Encoding Protocol Functions
-(void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:pRoot];
}
-(id)initWithCoder:(NSCoder *)coder
{
self = [super init];
pRoot = [[coder decodeObject] retain];
return self;
}
//********** End Encoding Protocol Functions
The HighScore class has an NSMutableDictionary instance variable as well
as pointers (?) to two other nodes (also of the HighScore class).
This is the encoding for the HighScore:
//********** Encoding Protocol Functions
-(void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:info];
[coder encodeObject:pLeftChild];
[coder encodeObject:pRightChild];
}
-(id)initWithCoder:(NSCoder *)coder
{
self = [super init];
info = [[coder decodeObject] retain];
pLeftChild = [[coder decodeObject] retain];
pRightChild = [[coder decodeObject] retain];
return self;
}
//********** End Encoding Protocol Functions
I suspect the problem lies with these pointers to other nodes. Do I
need to encode these pointers differently than other objects? (I seem
to recall a different @encode directive for pointers?) On the other
hand, I still want these nodes to be encoded as well and written to the
file, not just the pointers to them.
Any advice would be most appreciated,
Sincerely,
Nick
email@hidden
[Note: If you think that my recent posts to this list about files
("Low-level File Access", "File Question") have been unnecessary and a
waste of the list's time, I give my sincerest apologies and will refrain
(upon request) from asking such newbie questions in the future.]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.