- Codice:
void visit_r_backward(struct list *ptr) {
if (ptr != NULL) {
visit_r_backward(ptr->next_ptr);
printf("%f\n",ptr->value);
}
}
Non capisco come possano essere stampati gli elementi al contrario.
Grazie
void visit_r_backward(struct list *ptr) {
if (ptr != NULL) {
visit_r_backward(ptr->next_ptr);
printf("%f\n",ptr->value);
}
}
1°elemento
if (ptr != NULL) {
visit_r_backward(ptr->next_ptr); 2°elem
if (ptr != NULL) {
visit_r_backward(ptr->next_ptr); 3°elem
if (ptr != NULL) {
visit_r_backward(ptr->next_ptr);
printf("%f\n",ptr->value);
(visitr e printf non verranno eseguiti perchè il2°è l'ultimo elem)
(il 3°elem è un puntatore a NULL)
}
printf("%f\n",ptr->value);
}
printf("%f\n",ptr->value);
}
1°el |
if(è vero) |
ricorri -->| 2°el
| if(vero)
| ricorri --> | 3°el
| | if(falso)//il2° è l'ultimo elem quindi 3°
| | //sarà un puntatore a NULL
| | //Non ricorro e Non faccio Printf
| <--|- return;
| Printf(2°el) |
<--|- return;
Printf(1°el)|
return;//ritorna al Main
void visit_r_backward(struct list *ptr) {
if (ptr != NULL) {
printf("%f\n",ptr->value);
visit_r_backward(ptr->next_ptr);
}
}
Visitano il forum: Nessuno e 1 ospite