-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
87 lines (63 loc) · 1.37 KB
/
stack.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stack.h"
#include "main.h"
Stack new_stack(void)
{
return NULL;
}
/*-----------------------------------------------------------------*/
int is_empty_stack(Stack st)
{
if(st == NULL)
{
return 1;
}
return 0;
}
/*-----------------------------------------------------------------*/
Stack push_stack(Stack st, Virus p)
{
StackElement *element;
element = malloc(sizeof(*element));
if(element == NULL)
{
fprintf(stderr, "Probleme allocation dynamique.\n");
exit(EXIT_FAILURE);
}
strcpy(element->pv.virusName, p.virusName);
strcpy(element->pv.VirusPath, p.VirusPath);
element->next = st;
return element;
}
/*-----------------------------------------------------------------*/
Stack pop_stack(Stack st)
{
StackElement *element;
if(is_empty_stack(st))
{
return new_stack();
}
element = st->next;
free(st);
return element;
}
/*-----------------------------------------------------------------*/
Stack clear_stack(Stack st)
{
while(!is_empty_stack(st))
{
st = pop_stack(st);
}
return new_stack();
}
/*-----------------------------------------------------------------*/
Virus add_virus(char *name, char *path)
{
Virus p;
memset(&p, 0, sizeof(Virus));
strncpy(p.virusName, name, sizeof(p.virusName) - 1);
strncpy(p.VirusPath, path, sizeof(p.VirusPath) - 1);
return p;
}