My library
Library for common tasks
Functions
queue.h File Reference

Functions for working with Queue type. More...

#include "types.h"
Include dependency graph for queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Queue newQueue (const spec_t spec)
 Allocate a new Queue of specified type. More...
 
void enqueue (Queue queue,...)
 Enqueue an item into a Queue. More...
 
void dequeue (Queue queue, void *dest)
 Dequeue an item from a Queue. More...
 
void printQueue (const spec_t spec, const Queue queue)
 Print contents from a Queue. More...
 
unsigned int getQueueLength (const Queue queue)
 Get the size of a Queue. More...
 
void deleteHeadFromQueue (Queue queue)
 Delete current Queue head. More...
 
void peekQueue (const Queue queue, void *dest)
 Get the item in the head of a Queue without dequeueing it. More...
 
void deleteQueue (Queue queue)
 Delete a Queue. More...
 
byte isInQueue (Queue queue,...)
 Detect if an item is inside a Queue. More...
 
Queue chooseNewQueueFromArray (const spec_t spec, const void *arr, unsigned int size)
 Create a Queue from an array. More...
 
void enqueueFromPtr (Queue queue, const void *element)
 Enqueue an item into a Queue. More...
 
byte isQueueEmpty (Stack stack)
 Check if Queue is empty. More...
 
Queue newQueueFromCharArray (const char arr[], unsigned int size)
 Create a Queue from an array of chars. More...
 
Queue newQueueFromIntArray (const int arr[], unsigned int size)
 Create a Queue from an array of integers. More...
 
Queue newQueueFromFloatArray (const float arr[], unsigned int size)
 Create a Queue from an array of floats. More...
 
Queue newQueueFromDoubleArray (const double arr[], unsigned int size)
 Create a Queue from an array of doubles. More...
 
Queue newQueueFromPtrArray (const void *arr, unsigned int size)
 Create a Queue from an array of pointers. More...
 
byte areQueuesEqual (const Queue queue1, const Queue queue2)
 Compare two Queue. More...
 

Detailed Description

Functions for working with Queue type.

Author
Pietro Firpo (pietr.nosp@m.o.fi.nosp@m.rpo@p.nosp@m.m.me)

Function Documentation

◆ areQueuesEqual()

byte areQueuesEqual ( const Queue  queue1,
const Queue  queue2 
)

Compare two Queue.

Parameters
queue1The first Queue you want to compare
queue2The second Queue you want to compare
Returns
The result of the comparison
Return values
TRUEQueue1 and Queue2 have equal type and equal contents
FALSEQueue1 and Queue2 do not have equal type or equal contents

◆ chooseNewQueueFromArray()

Queue chooseNewQueueFromArray ( const spec_t  spec,
const void *  arr,
unsigned int  size 
)

Create a Queue from an array.

Parameters
specThe type specifier of the array passed. Refer to spec_t for supported types
arrThe array you want to create a Queue from
sizeThe number of items in arr
Returns
A Queue containing the elements in arr, having the first element of arr as head

◆ deleteHeadFromQueue()

void deleteHeadFromQueue ( Queue  queue)

Delete current Queue head.

Parameters
queueThe Queue you want to delete the head from

◆ deleteQueue()

void deleteQueue ( Queue  queue)

Delete a Queue.

Parameters
queueThe Queue you want to delete

◆ dequeue()

void dequeue ( Queue  queue,
void *  dest 
)

Dequeue an item from a Queue.

Parameters
queueThe Queue you want to dequeue from
destThe address of the variable you want to store the dequeued item in

◆ enqueue()

void enqueue ( Queue  queue,
  ... 
)

Enqueue an item into a Queue.

Parameters
queueThe Queue you want to enqueue an item into
...The item you want to enqueue into queue
Note
Even though enqueueing more than one item for single call does not throw a compiler nor runtime error, only enqueueing one item is supported. Other items are ignored and are not enqueued into queue. If you don't specify any item to be enqueued, still no errors occur but the content of your Queue can be messed up

◆ enqueueFromPtr()

void enqueueFromPtr ( Queue  queue,
const void *  element 
)

Enqueue an item into a Queue.

Parameters
queueThe Queue you want to enqueue an item into
elementPointer to the item you want to enqueue into queue

◆ getQueueLength()

unsigned int getQueueLength ( const Queue  queue)

Get the size of a Queue.

Parameters
queueThe Queue you want to evaluate
Returns
The number of elements in queue

◆ isInQueue()

byte isInQueue ( Queue  queue,
  ... 
)

Detect if an item is inside a Queue.

Parameters
queueThe Queue you want search in
...The element you want to search
Note
This function does not support float and double Queue types
Even though specifying more than one item for single call does not throw a compiler nor runtime error, only searching one item is supported. Other items are ignored. If you don't specify any item to be searched, still no errors occur but the return value of the function can be unpredictable
Return values
TRUEGiven element is contained in queue
FALSEGiven element is not contained in queue

◆ isQueueEmpty()

byte isQueueEmpty ( Stack  stack)

Check if Queue is empty.

Parameters
stackThe Queue to be checked
Return values
TRUEqueue is empty
FALSEqueue is not empty

◆ newQueue()

Queue newQueue ( const spec_t  spec)

Allocate a new Queue of specified type.

Parameters
specType specifier of the Queue you want to create. Refer to spec_t for supported types
Returns
An empty Queue

◆ newQueueFromCharArray()

Queue newQueueFromCharArray ( const char  arr[],
unsigned int  size 
)

Create a Queue from an array of chars.

Equivalent to chooseNewQueueFromArray("%c", arr, size). Refer to chooseNewQueueFromArray()

◆ newQueueFromDoubleArray()

Queue newQueueFromDoubleArray ( const double  arr[],
unsigned int  size 
)

Create a Queue from an array of doubles.

Equivalent to chooseNewQueueFromArray("%lf", arr, size). Refer to chooseNewQueueFromArray()

◆ newQueueFromFloatArray()

Queue newQueueFromFloatArray ( const float  arr[],
unsigned int  size 
)

Create a Queue from an array of floats.

Equivalent to chooseNewQueueFromArray("%f", arr, size). Refer to chooseNewQueueFromArray()

◆ newQueueFromIntArray()

Queue newQueueFromIntArray ( const int  arr[],
unsigned int  size 
)

Create a Queue from an array of integers.

Equivalent to chooseNewQueueFromArray("%i", arr, size). Refer to chooseNewQueueFromArray()

◆ newQueueFromPtrArray()

Queue newQueueFromPtrArray ( const void *  arr,
unsigned int  size 
)

Create a Queue from an array of pointers.

Equivalent to chooseNewQueueFromArray("%p", arr, size). Refer to chooseNewQueueFromArray()

◆ peekQueue()

void peekQueue ( const Queue  queue,
void *  dest 
)

Get the item in the head of a Queue without dequeueing it.

Parameters
queueThe Queue you want to get the item in the head from
destThe address of the variable you want to store the item in

◆ printQueue()

void printQueue ( const spec_t  spec,
const Queue  queue 
)

Print contents from a Queue.

Parameters
specThe type and format specifier you want to use to print the single element of the Queue. Use the printf() conventions
queueThe Queue you want to print