Search This Blog

Sunday, September 21, 2014

WAP to add all node value within a given range in SLL

1:  int sum_of_nodes(int pos1,int pos2)  
2:  {  
3:    int sum = 0;  
4:    int i;  
5:    list_t *temp = NULL;  
6:    for(i=1,temp = start;temp;temp = temp->next,i++)  
7:    {  
8:      if ( i >= pos1 && i <= pos2)  
9:      {  
10:        sum += temp->data;  
11:      }  
12:    }  
13:    return sum;  
14:  }  

No comments:

Post a Comment