ch4
asked on
recursion to iteration
/*structure definition*/
struct data{ char partno[6];
float cost;
int quan;
};
struct node{ struct data dat;
struct node * link;
};
/*pre: hd points to a node(usually the first)
post: the contents of all the nodes from that initial node pointed to by hd to the end of the listhave been printed*/
void print_list(struct node *hd)
{if(hd!= NULL)
{printf("%s %f %d\n", hd ->dat.partno, hd>dat.cost, hd ->dat.quan);
print_list(hd ->link);
}
}
this is a recursive function for printing the elements on a list. How can i write a new implementation of the function that does not use recursion but iteration instead.
struct data{ char partno[6];
float cost;
int quan;
};
struct node{ struct data dat;
struct node * link;
};
/*pre: hd points to a node(usually the first)
post: the contents of all the nodes from that initial node pointed to by hd to the end of the listhave been printed*/
void print_list(struct node *hd)
{if(hd!= NULL)
{printf("%s %f %d\n", hd ->dat.partno, hd>dat.cost, hd ->dat.quan);
print_list(hd ->link);
}
}
this is a recursive function for printing the elements on a list. How can i write a new implementation of the function that does not use recursion but iteration instead.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
All rbr has done is regurgitate ozo's answer. Give the points
to ozo.
to ozo.
printf("%s %f %d\n", hd ->dat.partno, hd>dat.cost, hd->dat.quan);
hd = hd ->link;
}