File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ #include "lists.h"
2+
3+ /**
4+ * get_dnodeint_at_index - get nth node of a dlistint_t linked list
5+ * @head: header of double linked list
6+ * @index: index of the node, starting from 0
7+ * Return: a address of nth node
8+ */
9+ dlistint_t * get_dnodeint_at_index (dlistint_t * head , unsigned int index )
10+ {
11+ dlistint_t * headcopy ;
12+ unsigned int i ;
13+
14+ headcopy = head ;
15+ if (headcopy != NULL )
16+ {
17+ while (headcopy -> prev != NULL )
18+ headcopy = headcopy -> prev ;
19+
20+ for (i = 0 ; (i < index ) && (headcopy != NULL ); i ++ )
21+ headcopy = headcopy -> next ;
22+ return (headcopy );
23+ }
24+ else
25+ return (NULL );
26+ }
Original file line number Diff line number Diff line change 1+ #include "lists.h"
2+
3+ /**
4+ * sum_dlistint - sum of all the data (n) of a dlistint_t linked list
5+ * @head: header of double linked list
6+ * Return: the sum of all nodes
7+ */
8+ int sum_dlistint (dlistint_t * head )
9+ {
10+ dlistint_t * headcopy ;
11+ int sum = 0 ;
12+
13+ headcopy = head ;
14+ if (headcopy != NULL )
15+ {
16+ while (headcopy -> prev != NULL )
17+ headcopy = headcopy -> prev ;
18+
19+ while (headcopy != NULL )
20+ {
21+ sum += headcopy -> n ;
22+ headcopy = headcopy -> next ;
23+ }
24+ return (sum );
25+ }
26+ else
27+ return (0 );
28+ }
You can’t perform that action at this time.
0 commit comments