Skip to content

Commit fff79dd

Browse files
committed
tasks
2 parents 49c3e48 + b19193c commit fff79dd

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "lists.h"
2+
3+
/**
4+
* add_dnodeint_end - add a node at the end of a double linked list
5+
* @head: header of double linked list
6+
* @n: number to set in a new node
7+
* Return: address of a new element
8+
*/
9+
dlistint_t *add_dnodeint_end(dlistint_t **head, const int n)
10+
{
11+
dlistint_t *new, *headcopy;
12+
13+
headcopy = *head;
14+
15+
if (head == NULL)
16+
return (NULL);
17+
18+
new = malloc(sizeof(dlistint_t));
19+
if (new == NULL)
20+
return (NULL);
21+
22+
new->n = n;
23+
24+
if (*head == NULL)
25+
{
26+
new->next = NULL;
27+
new->prev = NULL;
28+
*head = new;
29+
}
30+
else
31+
{
32+
while (headcopy->next != NULL)
33+
headcopy = headcopy->next;
34+
new->next = NULL;
35+
new->prev = headcopy;
36+
headcopy->next = new;
37+
}
38+
39+
return (new);
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "lists.h"
2+
3+
/**
4+
* free_dlistint - free a double linked list
5+
* @head: header of double linked list
6+
* Return: nothing
7+
*/
8+
void free_dlistint(dlistint_t *head)
9+
{
10+
dlistint_t *savepoin;
11+
12+
if (head != NULL)
13+
{
14+
while (head->prev != NULL)
15+
head = head->prev;
16+
17+
while (head != NULL)
18+
{
19+
savepoin = head->next;
20+
free(head);
21+
head = savepoin;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)