In this problem you will implement a function for a singly-linked list for geting the sum of the nodes.
Format of functions:
ElementType getSum(List L);
The parameter L
is a pointer to the dummy header. The function return the sum of the nodes of a Singly Linked List with dummy header.
where List
is defined as the following:
typedef int ElementType;
struct Node
{
ElementType data;
struct Node* next;
};
typedef struct Node* PtrToNode;
typedef PtrToNode List;
A singly linked list is a data structure in which an element has two parts one is the value and other is the link to the next element. So to find the sum of all elements of the singly linked list, we have to navigate to each node of the linked list and add the element's value to a sum variable.
For example</