Recursion

We are trying to go through a linked list and add all the values together and then return the sum using recursion. Can anyone help us with this please?

1
2
3
4
5
6
7
8
9
10
//Adds the values in the Linked List by recursion
template<class type>
double stack<type> :: sum()
{
        node<type> * tmp = new node<type>;
        int t = 0;
        tmp -> next = head;
        t = t + tmp -> data;
        tmp -> next = tmp -> next;
} 

Last edited on
Okay, good for us.
closed account (D80DSL3A)
See this thread: http://www.cplusplus.com/forum/beginner/37056/ for a working example of a recursive sum() on a linked list.
Topic archived. No new replies allowed.