-
Notifications
You must be signed in to change notification settings - Fork 0
/
aid_list2.c
61 lines (53 loc) · 1.13 KB
/
aid_list2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "main.h"
/**
* addtion_of_reverseNode -let's you add a variable at the end of the node
* of a r_var list.
* @head: head of the linked list.
* @lvar: length of the variable.
* @val: value of the variable.
* @lval: length of the value.
* Return: address of the head.
*/
r_var *addtion_of_reverseNode(r_var **head, int lvar, char *val, int lval)
{
r_var *first, *temporaryVariable;
first = malloc(sizeof(r_var));
if (first == NULL)
return (NULL);
first->len_var = lvar;
first->val = val;
first->len_val = lval;
first->next = NULL;
temporaryVariable = *head;
if (temporaryVariable == NULL)
{
*head = first;
}
else
{
while (temporaryVariable->next != NULL)
temporaryVariable = temporaryVariable->next;
temporaryVariable->next = first;
}
return (*head);
}
/**
* empty_of_reverselist - frees a r_var list
* @head: head of the linked list.
* Return: no return.
*/
void empty_of_reverselist(r_var **head)
{
r_var *temporaryVariable;
r_var *curr;
if (head != NULL)
{
curr = *head;
while ((temporaryVariable = curr) != NULL)
{
curr = curr->next;
free(temporaryVariable);
}
*head = NULL;
}
}