Repository navigation
Expand file tree
/
Copy pathqueue.h
More file actions
86 lines (72 loc) · 2.82 KB
/
Copy pathqueue.h
File metadata and controls
86 lines (72 loc) · 2.82 KB
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
#ifndef _QUEUE_H
#define _QUEUE_H
#include "linked_list.h"
// Some rules for Pointer Wars 2025 week 2:
// 0. Implement all functions in queue.c
// 1. Feel free to add members to the structures, but please do not remove
// any or rename any. Doing so will cause test infrastructure to fail
// to link against your shared library.
// 2. Same goes for the function declarations.
// 3. In your implementation, make use of malloc_fptr() and free_fptr()
// functions for memory allocation and memory freeing. This allows
// test infrastructure a bit more flexility. See linked_list.c for
// declarations of those function pointers.
// Definition of the queue.
//
struct queue {
struct linked_list* ll;
};
// Creates a new queue.
// PRECONDITION: Register malloc() and free() functions via the
// queue_register_malloc() and
// queue_register_free() functions.
// Returns a new linked_list on success, NULL on failure.
//
struct queue * queue_create(void);
// Deletes a linked_list.
// \param queue : Pointer to queue to delete
// Returns TRUE on success, FALSE otherwise.
//
bool queue_delete(struct queue * queue);
// Pushes an unsigned int onto the queue.
// \param queue : Pointer to queue.
// \param data : Data to insert.
// Returns TRUE on success, FALSE otherwise.
//
bool queue_push(struct queue * queue, unsigned int data);
// Pops an unsigned int from the queue, if one exists.
// \param queue : Pointer to queue.
// \param popped_data : Pointer to popped data (provided by caller), if pop occurs.
// Returns TRUE on success, FALSE otherwise.
//
bool queue_pop(struct queue * queue, unsigned int * popped_data);
// Returns the size of the queue.
// \param queue : Pointer to queue.
// Returns size on success, SIZE_MAX otherwise.
//
size_t queue_size(struct queue * queue);
// Returns whether an entry exists to be popped.
// \param queue: Pointer to queue.
// Returns TRUE if an entry can be popped, FALSE otherwise.
//
bool queue_has_next(struct queue * queue);
// Returns the value at the head of the queue, but does
// not pop it.
// \param queue : Pointer to queue.
// \param popped_data : Pointer to popped data (provided by caller), if pop occurs.
// Returns TRUE on success, FALSE otherwise.
//
bool queue_next(struct queue * queue, unsigned int * popped_data);
// Registers malloc() function.
// \param malloc : Function pointer to malloc()-like function.
// POSTCONDITION: Initializes malloc() function pointer in linked_list.
// Returns TRUE on success, FALSE otherwise.
//
bool queue_register_malloc(void * (*malloc)(size_t));
// Registers free() function.
// \param free : Function pointer to free()-like function.
// POSTCONDITION: Initializes free() functional pointer in linked_list.
// Returns TRUE on success, FALSE otherwise.
//
bool queue_register_free(void (*free)(void*));
#endif