SilverMage's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
40 (0.03 per day)
Joined:
11-October 10
Profile Views:
1,299
Last Active:
User is offline Apr 10 2013 07:05 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   SilverMage has not set their status

Posts I've Made

  1. In Topic: C thread accepting same connection twice, results in failure

    Posted 6 Mar 2013

    Never mind, it seems I have fixed my problem
  2. In Topic: How to find out if a client has disconnected from server.

    Posted 5 Mar 2013

    Yes, that one precisely
  3. In Topic: How to find out if a client has disconnected from server.

    Posted 5 Mar 2013

    Well, a server that is capable of handling multiple clients using the select() function. Basically, think of a chat server.
  4. In Topic: How come an insert to a binary tree struct doesn't work this way

    Posted 8 Oct 2012

    View PostSalem_c, on 08 October 2012 - 08:20 AM, said:

    void foo ( int a ) {
      a = 42;
    }
    int bar ( void ) {
      return 42;
    }
    int main ( ) {
      int a = 0;
      foo(a);
      printf("%d\n", a );
      a = bar();
      printf("%d\n", a );
      return 0;
    }
    
    

    Do you understand why foo() doesn't work, and bar() does?

    One way is to declare
    struct node* insertNode(struct node* n, int x) {
      if ( n == NULL ) {
        n = malloc.....
      }
      return n;
    }
    
    

    Then do
    n->left = insertNode(n->left, x);

    Or you pass a pointer to the node itself (see your other thread).

    Or you switch to C++, and use a reference instead.



    Hmmm, Now I see why that tutorial told me to use a pointer to the node. Now that I see, the root is a pointer itself, so the method makes sense now. Thanks, Salem, I just wanted to understand the tutorial better
  5. In Topic: How come an insert to a binary tree struct doesn't work this way

    Posted 8 Oct 2012

    View PostSkydiver, on 08 October 2012 - 07:58 AM, said:

    Your line 9 crashes because no where in the code you've post are you setting/updating the pointer to the root node.

    Are you setting the root pointer elsewhere, or are you assuming a code call like this will update the root?
    struct node * root = NULL;
    insertNode(root, 25);
    
    

    Given your current insertNode() method, root will not be updated.



    View PostSalem_c, on 08 October 2012 - 08:04 AM, said:

    http://www.dreaminco...to-binary-tree/
    Note the extra level of indirection in this example.

    > insertNode(n->left, x);
    This does NOT change n->left.



    Skydiver, I have my root set that way, but why won't my method update the root?

    Salem, I was able to get the method working that way, but it's got me curious as to why I have to use pointers to pointers instead of an intuitive way involving just the node or a pointer to it.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

SilverMage has no profile comments yet. Why not say hello?