-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.c
144 lines (114 loc) · 2.73 KB
/
lists.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
typedef struct record_data
{
int index;
char *first_name;
char *last_name;
char *occupation;
}record_data;
typedef struct list_node
{
void *record;
struct list_node *next;
}list_node_t;
int show_list(list_node_t *list);
int remove_entire_list(list_node_t **list);
int main(int argc, char* argv[])
{
record_data *entry;
char *first_name = "Vladimir\0";
char *last_name = "Baus\0";
char *occupation = "Engineer\0";
int index = 0;
list_node_t *list;
entry = (record_data*)malloc(sizeof(record_data));
entry->first_name = (char*)malloc(strlen(first_name));
strcpy(entry->first_name, first_name);
entry->last_name = (char*)malloc(strlen(last_name));
strcpy(entry->last_name, last_name);
entry->occupation = (char*)malloc(strlen(occupation));
strcpy(entry->occupation, occupation);
entry->index = index;
list = (list_node_t*)malloc(sizeof(list_node_t));
list->record = entry;
list->next = NULL;
show_list(list);
remove_entire_list(&list);
show_list(list);
return 1;
}
list_node_t *create_list()
{
return (list_node_t*)malloc(sizeof(list_node_t));
}
int add_head(list_node_t *new_node, list_node_t **list)
{
new_node->next = *list;
*list = new_node;
return 1;
}
int add_tail(list_node_t *new_node, list_node_t **list)
{
list_node_t *current = *list;
while(current->next!=NULL)
{
current = current->next;
}
return 1;
}
int add_at_index()
{
return 1;
}
int remove_head()
{
return 1;
}
int remove_tail()
{
return 1;
}
int remove_at_index()
{
return 1;
}
int remove_entire_list(list_node_t **list)
{
list_node_t *current=NULL;
current = *list;
if (current==NULL)
{
printf("The list is empty!\n");
return -1;
}
while (current!=NULL)
{
current = (*list)->next;
free(*list);
(*list) = current;
}
*list = NULL;
return 1;
}
int show_list(list_node_t *list)
{
list_node_t *current=NULL;
current = list;
if (current==NULL)
{
printf("The list is empty!\n");
return -1;
}
while (current!=NULL)
{
printf("Entry first name: %s\n", ((record_data*)list->record)->first_name);
printf("Entry last name: %s\n", ((record_data*)list->record)->last_name);
printf("Entry occupation: %s\n", ((record_data*)list->record)->occupation);
printf("Entry index: %d\n", ((record_data*)list->record)->index);
current=current->next;
}
return 1;
}