forked from bluefeversoft/c_linked_lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linked_lists_2.c
91 lines (51 loc) · 1.28 KB
/
linked_lists_2.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
#include <stdio.h>
#include <stdlib.h>
struct sPerson {
int age;
struct sPerson *nextInLine;
};
struct sPerson *getNewPerson(const int age)
{
struct sPerson *newPerson = NULL;
newPerson = malloc(sizeof(struct sPerson));
newPerson->nextInLine = NULL;
newPerson->age = age;
printf("created new person at %p\n", newPerson);
return newPerson;
}
void printPerson(const struct sPerson *person, const char *comment)
{
if (person == NULL)
{
printf("%s is NULL\n", comment);
}
else
{
printf("%s: age:%d address:%p nextInLine:%p\n",
comment,
person->age,
person,
person->nextInLine);
}
}
int main()
{
printf("\n\n** START **\n\n");
struct sPerson *first = NULL;
struct sPerson *second = NULL;
printPerson(first, "first");
printPerson(second, "second");
first = getNewPerson(125);
second = getNewPerson(100);
printPerson(first, "first");
printPerson(second, "second");
first->nextInLine = second;
printPerson(first, "First");
printPerson(first->nextInLine, "first->nextInLine");
printPerson(second, "Second");
free(first);
free(second);
first = NULL;
second = NULL;
return 0;
}