using of * &

B

Burak

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
 
V

vippstar

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:
 
R

Richard Heathfield

Burak said:
void DeleteNode(struct node * & node) {

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...
 
S

santosh

Burak wrote:

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 <instead of
<news:comp.lang.c++>?
 
P

Paul Sinnett

Burak said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Infinite loop problem 1
Queue in C 25
Didn't get Ben Pfaff code (chapter 12 of The Book). 15
tree 6
comparing binary trees in C 12
Balancing a Binary Tree 4
simplebinary tree 7
error in binary tree 13

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top