4.) Rewrite the following recursive function to use iteration with an explicit s
ID: 3841201 • Letter: 4
Question
4.) Rewrite the following recursive function to use iteration with an explicit
stack.
int p r e o r d e r ( Tree t )
{
s t d : : cou t << t . item << s t d : : e o l ;
i f ( t . l e f t ) {
p r e o r d e r ( t . l e f t ) ;
}
i f ( t . r i g h t ) {
p r e o r d e r ( t . r i g h t ) ;
}
}
5.)Assume a linked list implementation identical to the 1st homework, or the
std::forward_list of the standard template library. Write a recursive function that
returns the sum of a linked list of integers given as its only argument.
int sum ( Lin k edLi s t <int> list_to_sum )
{
}