Repository navigation
Expand file tree
/
Copy pathlist.cpp
More file actions
68 lines (60 loc) · 1.3 KB
/
Copy pathlist.cpp
File metadata and controls
68 lines (60 loc) · 1.3 KB
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
//
// Created by Maximilian Nowak on 28.06.22.
//
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
list * l_init() {
list * lst = (list *)malloc(sizeof(list));
lst->head = NULL;
lst->count = 0;
return lst;
}
void l_insert(list * lst, char * word)
{
element * new_data = (element *)malloc(sizeof(element));
strcpy(new_data->word, word);
new_data->next = lst->head;
lst->head = new_data;
lst->count++;
}
void l_delete(list * lst, char * word)
{
element * tmp = lst->head;
element * prv = NULL;
while (tmp != NULL) {
if (strcmp(tmp->word, word) == 0) {
if (prv == NULL) {
lst->head = tmp->next;
}
else {
prv->next = tmp->next;
}
free(tmp);
lst->count--;
return;
}
prv = tmp;
tmp = tmp->next;
}
}
void l_print(list * lst) {
element * tmp = lst->head;
while (tmp != NULL) {
printf("%s: \n", tmp->word);
tmp = tmp->next;
}
}
element * l_find(list * lst, char * word)
{
element * tmp = lst->head;
while (tmp != NULL) {
if (strcmp(tmp->word, word) == 0) {
return tmp;
}
tmp = tmp->next;
}
return NULL;
}