list.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* list.h -- header file for a simple list type */
  2. #ifndef LIST_H_
  3. #define LIST_H_
  4. #include <stdbool.h> /* C99 feature */
  5. /* program-specific declarations */
  6. #define TSIZE 45 /* size of array to hold title */
  7. struct film
  8. {
  9. char title[TSIZE];
  10. int rating;
  11. };
  12. /* general type definitions */
  13. typedef struct film Item;
  14. typedef struct node
  15. {
  16. Item item;
  17. struct node * next;
  18. } Node;
  19. typedef Node * List;
  20. /* function prototypes */
  21. /* operation: initialize a list */
  22. /* preconditions: plist points to a list */
  23. /* postconditions: the list is initialized to empty */
  24. void InitializeList(List * plist);
  25. /* operation: determine if list is empty */
  26. /* plist points to an initialized list */
  27. /* postconditions: function returns True if list is empty */
  28. /* and returns False otherwise */
  29. bool ListIsEmpty(const List *plist);
  30. /* operation: determine if list is full */
  31. /* plist points to an initialized list */
  32. /* postconditions: function returns True if list is full */
  33. /* and returns False otherwise */
  34. bool ListIsFull(const List *plist);
  35. /* operation: determine number of items in list */
  36. /* plist points to an initialized list */
  37. /* postconditions: function returns number of items in list */
  38. unsigned int ListItemCount(const List *plist);
  39. /* operation: add item to end of list */
  40. /* preconditions: item is an item to be added to list */
  41. /* plist points to an initialized list */
  42. /* postconditions: if possible, function adds item to end */
  43. /* of list and returns True; otherwise the */
  44. /* function returns False */
  45. bool AddItem(Item item, List * plist);
  46. /* operation: apply a function to each item in list */
  47. /* plist points to an initialized list */
  48. /* pfun points to a function that takes an */
  49. /* Item argument and has no return value */
  50. /* postcondition: the function pointed to by pfun is */
  51. /* executed once for each item in the list */
  52. void Traverse (const List *plist, void (* pfun)(Item item) );
  53. /* operation: free allocated memory, if any */
  54. /* plist points to an initialized list */
  55. /* postconditions: any memory allocated for the list is freed */
  56. /* and the list is set to empty */
  57. void EmptyTheList(List * plist);
  58. #endif