using of * &

Discussion in 'C Programming' started by Burak, Dec 4, 2007.

  1. Burak

    Burak Guest

    void DeleteNode(struct node * & node) {
    if (node->left == NULL) {
    struct node *temp = node;
    node = node->right;
    delete temp;
    } else if (node->right == NULL) {
    struct node *temp = node;
    node = node->left;
    delete temp;
    } else {
    // In-order predecessor (rightmost child of left subtree)
    // Node has two children - get max of left subtree
    struct node **temp = &node->left; // get left node of the
    original node

    // find the rightmost child of the subtree of the left node
    while ((*temp)->right != NULL) {
    temp = &(*temp)->right;
    }

    // copy the value from the in-order predecessor to the
    original node
    node->value = (*temp)->value;

    // then delete the predecessor
    DeleteNode(*temp);
    }
    }


    i saw this function on wikipedia.
    what does * & mean there(struct node * & node) ?

    thanx Burak
    Burak, Dec 4, 2007
    #1
    1. Advertising

  2. Burak

    Guest

    On Dec 4, 4:16 pm, Burak <> wrote:
    > void DeleteNode(struct node * & node) {
    > <body>
    >
    > i saw this function on wikipedia.
    > what does * & mean there(struct node * & node) ?


    Nothing, it's invalid.
    Wikipedia for that example says:
    <http://en.wikipedia.org/wiki/Binary_search_tree#Deletion>
    > Here is C++ sample code for a destructive version of deletion. (We assume the node to be deleted has already been located using search.)
    , Dec 4, 2007
    #2
    1. Advertising

  3. Burak

    pete Guest

    Burak wrote:
    >
    > void DeleteNode(struct node * & node) {


    > delete temp;


    > i saw this function on wikipedia.
    > what does * & mean there(struct node * & node) ?


    That's not C code.

    --
    pete
    pete, Dec 4, 2007
    #3
  4. Burak said:

    > void DeleteNode(struct node * & node) {


    <snip>

    > i saw this function on wikipedia.
    > what does * & mean there(struct node * & node) ?


    It means either that the Wikipedia article, at the time you saw it, had
    most recently been edited by someone who doesn't know C[1], or perhaps it
    wasn't actually an article about C code. As far as the C language is
    concerned, the code you have shown constitutes a syntax error requiring a
    diagnostic message from your implementation. In other words, it's
    meaningless.


    [1] It wouldn't be the first time. Or the second. Or the third...

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Dec 4, 2007
    #4
  5. Burak

    santosh Guest

    Burak wrote:

    <snip code>

    > i saw this function on wikipedia.
    > what does * & mean there(struct node * & node) ?


    As vippstar points out, the Wikipedia page clearly mentions that it is
    C++ code. So why are you asking in <news:comp.lang.c> instead of
    <news:comp.lang.c++>?
    santosh, Dec 4, 2007
    #5
  6. Burak

    Paul Sinnett Guest

    Burak wrote:
    > i saw this function on wikipedia.
    > what does * & mean there(struct node * & node) ?


    It's c++ and it means that node is a reference to a pointer to a node.
    It's probably not a good idea to call the type and the variable by the
    same name though.
    Paul Sinnett, Dec 4, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    4
    Views:
    437
    Hans Kesting
    May 6, 2004
  2. Stan Accrington
    Replies:
    1
    Views:
    908
    Michael Borgwardt
    May 13, 2004
  3. Steve
    Replies:
    0
    Views:
    438
    Steve
    Jan 31, 2006
  4. Wayne...
    Replies:
    15
    Views:
    747
    Toby Inkster
    Jul 23, 2004
  5. Lance Riedel

    Translated Offset to Source Offset

    Lance Riedel, Oct 14, 2003, in forum: XML
    Replies:
    2
    Views:
    477
    Patrick TJ McPhee
    Oct 15, 2003
Loading...

Share This Page