Binary Tree in Objective-C

前端 未结 4 1890
一向
一向 2021-01-31 00:22

I am learning algorithms and data structures and to train I am trying to design and implement a binary tree using objective-c.

So far I have the following Classes:

4条回答
  •  自闭症患者
    2021-01-31 01:10

    (Node **)node is a pointer to an object pointer so node.something is invalid because you are a reference to far away from the object.

    But (*node).something will work.


    Addition for comments :
    When you originally call this method : -(void)insertNodeByRef:(Node **)node forRoot:(Node **)root how do you call it?
    From the error you've post in your comment it look to me that you are doing :
    Node *n = [[Node alloc] init];
    [aNode insertNodeByRef:n forRoot:aRoot];

    when your method signature state that you need to call it like this :
    [aNode insertNodeByRef:&n forRoot:&aRoot];
    To pass the address of the pointer to the object.

    I'm saying this because your error is now stating that your are sending Node * instead of Node ** which are 2 different thing. (( Incompatible pointer types sending 'Node *' to parameter of type 'Node **' ) I've remove the __autoreleasing between the 2 *, it was obscuring the error message.)
    So in other word you are passing a pointer to an object when your method is asking for a pointer TO A pointer to an object.

提交回复
热议问题