Hello, I'm asking you a question because there are parts in grammar that I don't understand well while studying the data structure.
typedef void VisitFuncPtr(BTData data);
void InorderTraverse (BTreeNode* bt, VisitFincPtraction) // Lieutenant Tour
{
If (bt == NULL) // If bt is NULL, recursive escape
return;
InorderTraverse (bt->left, action); // Stage 1 Tour of the left subtree
action(bt->data); // Step 2 root node visit
InorderTraverse (bt->right, action); // Stage 3 Tour of the right subtree
}
I think I only need a part of the sauce, so I'll put a part of the sauce on it, but if you need the whole sauce, I'll edit it and upload it.
In the book, there was a part where a function pointer was used in a source that traveled and visited nodes while studying binary trees.
You use a function pointer, but you use typedef void VisitFuncPtr(BTData data);
like the source above.
It was unfamiliar because it was my first time using a function pointer as a typeef, but I read it because I thought it was different from normal typeef
When I first saw this sentence, what was it? It's not the shape of the function pointer I know I thought so, but I kept reading it because I thought something would come out if I looked at the back. However, I don't understand well even if I read it, so I leave a message here.
If it's the shape of the function pointer that I studied when I studied the basics of C language,
void (*VisitFuncPtr) (BTData);
It should have looked like this.
Return type is void and pointer variable? The name is VisitFuncPtr, and the parameter data type is a function pointer with one BTData. Like this. And according to the grammar of the typeef that I studied, the nickname at the end? There should be the same thing, but there isn't. Like writing int as ABC in typedef int ABC
.
But it's embarrassing to write it like that and call it a function pointer.
Even in the following InorderTraverse (BTreeNode* bt, VisitFincPtraction) function, VisitFuncPtraction has no idea how to interpret this parameter.Is action the variable name of VisitFuncPtr? If so, VisitFuncPtr means type, but VisitFuncptr is a function pointer name, not type, but I'm confused
The action(bt->data);
part of the body is also blocked in the parameter, so it is confusing because it is not accurate to grasp something.
It seems like the grammar I usually knew, but it comes out a little different, so I don't understand it well I'm asking you a question because I don't know it, but I'd appreciate it if you could answer it.
c data-structure vs2017
The void (*VisitFuncPtr) (BTData); is the VisitFunctionPtr variable declaration. Therefore, VisitFuncPtr = a; is possible, but VisitFuncPtr; is not possible. Typeef void VisitFuncPtr (BTData data) in the book; Override variable types. Therefore, VisitFuncPtra; is possible and VisitFuncPtr = a; is not possible.
© 2024 OneMinuteCode. All rights reserved.