尾递归:
点击(此处)折叠或打开
-
/*Bad use of recursion:Printing a linked list*/
-
/*No header*/
-
void
-
PrintList(List L)
-
{
-
if (L != NULL) {
-
PrintElement(L->Element);
-
PrintList(L->Next);
-
}
- }
用goto消除尾递归:
点击(此处)折叠或打开
-
/*Bad use of recursion:Printing a linked list*/
-
/*No header*/
-
void
-
PrintList(List L)
-
{
-
top:
-
if (L != NULL) {
-
PrintElement(L->Element);
-
L = L->next;
- goto top;
-
}
- }