我给定的代码有一些问题。你它相应地工作,我需要实现“横向”和“横向R”功能。
我也很难理解给定的函数指针的用途:Function pointers => void (*visit)(link)
void traverse (link ls, void (*visit)(link)) {
if (ls == NULL) {
return;
}
(*visit) (ls);
traverse (ls->next, visit);
return;
}
void traverseR (link ls, void (*visit)(link)) {
if (ls == NULL) {
return;
}
traverseR (ls->next, visit);
(*visit)(ls);
return;
}
void square (link l) {
// link tmp = NULL;
int container = l->item;
container = SQUARE(container);
l->item = container;
}
void squareAll (link ls){
link curr = ls;
while (curr != NULL){
square(curr);
curr = curr->next;
}
ls = curr;
}