Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
vector.c File Reference

Implementation of vector structure and related functions. More...

#include "vector.h"

Go to the source code of this file.

Functions

vectorbuildVector ()
 Builds a vector structure initializing its fields. If vector's allocation or data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
void freeVector (vector *const vector)
 Frees the memory used from the vector structure.
void resize (vector *const vector, const size_t newCapacity)
 Resizes the capacity of the vector with the new capacity specified. If vector's data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
void pushBack (vector *const vector, const data_type element)
 Pushes an element at the back of the vector.
data_type popBack (vector *const vector)
 Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
void pushFront (vector *const vector, const data_type element)
 Pushes an element at the front of the vector. If necessary, the vector is resized automatically.
data_type popFront (vector *const vector)
 Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
data_type at (vector *vector, size_t index)
 Access at the element in the given index of the vector. If the index is greater or equal to the vector's size, it exits with EXIT_ILLEGAL_INDEX_FAILURE exit code.

Detailed Description

Implementation of vector structure and related functions.

Definition in file vector.c.

Function Documentation

◆ at()

data_type at ( vector * vector,
size_t index )

Access at the element in the given index of the vector. If the index is greater or equal to the vector's size, it exits with EXIT_ILLEGAL_INDEX_FAILURE exit code.

Parameters
vectorThe vector.
indexThe index to access to.
Returns
The element at the index position in the vector.

Definition at line 111 of file vector.c.

◆ buildVector()

vector * buildVector ( )

Builds a vector structure initializing its fields. If vector's allocation or data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.

Returns
A vector structure.

Definition at line 23 of file vector.c.

◆ freeVector()

void freeVector ( vector *const vector)

Frees the memory used from the vector structure.

Parameters
vectorThe vector to be free.

Definition at line 43 of file vector.c.

◆ popBack()

data_type popBack ( vector *const vector)

Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.

Parameters
vectorThe vector from which the element is poped.
Returns
Returns the element at the back of the vector.

Definition at line 70 of file vector.c.

◆ popFront()

data_type popFront ( vector *const vector)

Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.

Parameters
vectorThe vector from which the element is poped.
Returns
Returns the element at the front of the vector.

Definition at line 94 of file vector.c.

◆ pushBack()

void pushBack ( vector *const vector,
const data_type element )

Pushes an element at the back of the vector.

Parameters
vectorThe vector into the element has to be pushed. If necessary, the vector is resized automatically.
elementThe element to be pushed.

Definition at line 63 of file vector.c.

◆ pushFront()

void pushFront ( vector *const vector,
const data_type element )

Pushes an element at the front of the vector. If necessary, the vector is resized automatically.

Parameters
vectorThe vector into the element has to be pushed.
elementThe element to be pushed.

Definition at line 83 of file vector.c.

◆ resize()

void resize ( vector *const vector,
const size_t newCapacity )

Resizes the capacity of the vector with the new capacity specified. If vector's data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.

Parameters
vectorThe vector that has to be resized.
newCapacityThe new capacity of the vector.

Definition at line 48 of file vector.c.