Binary Tree and Objective-c

Posts: 4
Joined: 2009.09
Post: #1
I am learning Objective-c at this moment. Read Stephen Kochan's book and now I am trying to write a binary tree.
My head isn't completely thinking Objective-c yet.

Has anyone implemented a simple BT in Objective-c and wouldn't mind sharing the code?

This is where I am at..
#import <Foundation/Foundation.h>

// define the class interface
@interface Node : NSObject
    Node *left;
    Node *right;
    int value;

-(void) InsertValue: (int) ivalue;

@implementation Node
-(void) InsertValue: (int) ivalue
    value = ivalue;


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Node *root = [[Node alloc]init];
    [root InsertValue: 5];
    // insert code here...
    [pool drain];
    return 0;
How would I set up the constructor? I am confused as to how to write the InsertValue in Objective-c.

Google didn't turn up anything on Objective-C and BTs. Nor did a search through this forum.



Edit by mod (wyrmmage): Please surround your code in code tags for better clarity. I've done it for you this time Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Reading Binary Files Nick 15 6,626 Jul 12, 2005 03:53 AM
Last Post: sealfin