forked from sgreenlee/C-Primer-Plus-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
film.c
49 lines (42 loc) · 921 Bytes
/
film.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
// film.c -- implementation file for linked film list
#include "film.h"
// delete the entire film list and free allocated memory
void delete_list(List * list_ptr)
{
Film * tmp, * list = *list_ptr;
while (list != NULL)
{
tmp = list->next;
free(list);
list = tmp;
}
*list_ptr = NULL;
}
// add a film to the list;
void add_film(List filmlist, Film * new_film)
{
Film * film_ptr = filmlist;
while (film_ptr->next != NULL)
film_ptr = film_ptr->next;
film_ptr->next = new_film;
}
// print the list of films in original order
void list_films(List film_ptr)
{
while (film_ptr != NULL)
{
printf("%s: %d\n", film_ptr->title, film_ptr->rating);
film_ptr = film_ptr->next;
}
}
// print the list of films in reverse order
void reverse_list_films(List film_ptr)
{
if (film_ptr == NULL)
return;
else
{
reverse_list_films(film_ptr->next);
printf("%s: %d\n", film_ptr->title, film_ptr->rating);
}
}