LibRCG  3.1.1
queue.h File Reference

Implementation of a queue as linked list. More...

Go to the source code of this file.

Data Structures

struct  SQueueNode
 Queue node structure. More...
 
struct  SQueue
 Queue structure. More...
 

Typedefs

typedef SQueueNodeQueueNode
 Queue node definition. More...
 
typedef SQueueQueue
 Queue definition. More...
 

Functions

Queue newQueue (void)
 Creates a queue. More...
 
void queueDelete (Queue queue)
 Deletes a queue. More...
 
int queueInsert (Queue queue, void *value)
 Inserts an element in a queue. More...
 
int queueRemove (Queue queue, void **value)
 Removes an element from a queue. More...
 
int queueConsult (Queue queue, void **value)
 Provides the value at the head of a queue. More...
 
int queueSize (Queue queue)
 Returns the size of a queue. More...
 
int queueMap (Queue queue, void(*fun)(void *))
 Applies a function to the elements of a queue. More...
 
Iterator queueIterator (Queue queue)
 Creates an iterator from a queue. More...
 

Detailed Description

Implementation of a queue as linked list.

Provides functions to create and manipulate a queue.

Author
Rui Carlos Gonçalves
Version
3.0.1
Date
01/2014

Definition in file queue.h.

Typedef Documentation

typedef SQueue* Queue

Queue definition.

Definition at line 49 of file queue.h.

Queue node definition.

Definition at line 30 of file queue.h.

Function Documentation

Queue newQueue ( void  )

Creates a queue.

Returns
NULL if an error occurred
the new queue otherwise

Definition at line 12 of file queue.c.

int queueConsult ( Queue  queue,
void **  value 
)

Provides the value at the head of a queue.

If the queue is empty, it will be put the value NULL at value.

Attention
This function puts at value a pointer to the value at the first position. Changes to this value will affect the element in the list.
Parameters
queuethe queue
valuepointer where the value at the last position will be put
Returns
0 if the queue was not empty
1 otherwise

Definition at line 95 of file queue.c.

void queueDelete ( Queue  queue)

Deletes a queue.

Attention
This function only frees the memory used by the queue. It does not free the memory used by elements the queue contains.
Parameters
queuethe queue to be deleted

Definition at line 26 of file queue.c.

int queueInsert ( Queue  queue,
void *  value 
)

Inserts an element in a queue.

Parameters
queuethe queue
valuethe value to be inserted
Returns
0 if the new value was inserted
1 if it was not possible to insert the new element

Definition at line 44 of file queue.c.

Iterator queueIterator ( Queue  queue)

Creates an iterator from a queue.

See Also
Iterator
Parameters
queuethe queue
Returns
NULL if an error occurred
the iterator otherwise

Definition at line 131 of file queue.c.

int queueMap ( Queue  queue,
void(*)(void *)  fun 
)

Applies a function to the elements of a queue.

The function to be applied must be of type void fun(void*).

Parameters
queuethe queue
funthe function to be applied
Returns
0 if the queue was not empty
1 otherwise

Definition at line 116 of file queue.c.

int queueRemove ( Queue  queue,
void **  value 
)

Removes an element from a queue.

Provides the value of the removed element if the value of value is not NULL.

Attention
This function does not free the memory used by the removed element.
Parameters
queuethe queue
valuepointer where the removed value should be put (or NULL)
Returns
0 if an element was removed
1 if the queue was empty

Definition at line 64 of file queue.c.

int queueSize ( Queue  queue)

Returns the size of a queue.

Parameters
queuethe queue
Returns
the size of the queue

Definition at line 109 of file queue.c.

LibRCG © 2004-2015   Rui Carlos Gonçalves