-
Notifications
You must be signed in to change notification settings - Fork 124
/
list2.h
74 lines (56 loc) · 2.16 KB
/
list2.h
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
/* list.h -- header file for a simple list type */
#ifndef LIST_H_
#define LIST_H_
#include <stdbool.h>
#define TSIZE 45 /* size of array to hold title */
#define MAXSIZE 100
struct film
{
char title[TSIZE];
int rating;
};
/* general type definitions */
typedef struct film Item;
typedef struct list {
Item entries[MAXSIZE]; /* array of items */
int items; /* number of items in list */
} List;
/* function prototypes */
// operation: initialize a list
// preconditions: plist points to a list
// postcondition: the list is initialized to empty
void InitializeList(List * plist);
// operation: determine if list is empty
// preconditions: plist points to an initialized list
// postcondition: function returns true if list is empty
// and false otherwise
bool ListIsEmpty(const List *plist);
// operation: determine if list is full
// preconditions: plist points to an initialized list
// postcondition: function returns true if list is full and false
// otherwise
bool ListIsFull(const List *plist);
// operation: determine number of items in list
// preconditions: plist points to an initialized list
// postconditions: function returns number of items in list
unsigned int ListItemCount(const List *plist);
// operation: add item to end of list
// preconditions: item is an item to be added to list
// plist points to an initialized list
// postcondition: if possible, function adds item to end
// of list and returns True; otherwise the
// function returns False
bool AddItem(Item item, List * plist);
// operation: apply a function to each item in list
// preconditions: plist points to an initialized list
// pfun points to a function that takes an
// Item argument and has no return value
// postcondition: the function pointed to by pfun is
// executed once for each item in the list
void Traverse (const List *plist, void (* pfun)(Item item) );
// operation: free allocated memory, if any
// preconditions: plist points to an initialized list
// postcondition: any memory allocated for the list is freed
// and the list is set to empty
void EmptyTheList(List * plist);
#endif