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

Functions for working with LinkedList type. More...

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

Go to the source code of this file.

Functions

LinkedList newLL (const spec_t spec)
 Allocate a new LinkedList of specified type. More...
 
LinkedList chooseNewLLFromArray (const spec_t spec, const void *arr, unsigned int size)
 Create a LinkedList from an array. More...
 
void printLL (const spec_t spec, const LinkedList list)
 Print contents from a LinkedList. More...
 
void appendToLL (LinkedList list,...)
 Insert an item at the end of a LinkedList. More...
 
void appendToLLFromPtr (LinkedList list, const void *element)
 Insert an item at the end of a LinkedList. More...
 
void insertToLL (LinkedList list, unsigned int index,...)
 Insert an element at a specified position of a LinkedList. More...
 
void deleteLL (LinkedList list)
 Delete a LinkedList. More...
 
void getFromLL (LinkedList list, unsigned int index, void *dest)
 Get an item from a LinkedList. More...
 
void setLLItem (LinkedList list, unsigned int index,...)
 Set value of an element of a LinkedList. More...
 
void removeFromLL (LinkedList list, unsigned int index)
 Remove an item from a LinkedList. More...
 
void mergeLL (LinkedList list1, const LinkedList list2)
 Merge two LinkedList. More...
 
LinkedList newLLFromLL (const LinkedList list)
 Get a copy of a LinkedList. More...
 
void sliceLL (LinkedList list, unsigned int begin, unsigned int end)
 Slice a LinkedList. More...
 
int linearSearchLL (LinkedList list,...)
 Linear search for LinkedList. More...
 
void * linearSearchLLPtr (LinkedList list,...)
 Linear search for LinkedList. More...
 
byte areLLEqual (const LinkedList list1, const LinkedList list2)
 Compare two LinkedList. More...
 
byte isInLL (LinkedList list,...)
 Detect if an element is inside a LinkedList. More...
 
unsigned int getLLLength (const LinkedList list)
 Get the size of a LinkedList. More...
 
LinkedList newLLFromCharArray (const char arr[], unsigned int size)
 Create a LinkedList from a array of chars. More...
 
LinkedList newLLFromIntArray (const int arr[], unsigned int size)
 Create a LinkedList from a array of ints. More...
 
LinkedList newLLFromFloatArray (const float arr[], unsigned int size)
 Create a LinkedList from a array of floats. More...
 
LinkedList newLLFromDoubleArray (const double arr[], unsigned int size)
 Create a LinkedList from an array of doubles. More...
 
LinkedList newLLFromPtrArray (const void *arr, unsigned int size)
 Create a LinkedList from an array of pointers. More...
 
byte isLLEmpty (LinkedList list)
 Check if LinkedList is empty. More...
 

Detailed Description

Functions for working with LinkedList type.

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

Function Documentation

◆ appendToLL()

void appendToLL ( LinkedList  list,
  ... 
)

Insert an item at the end of a LinkedList.

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

◆ appendToLLFromPtr()

void appendToLLFromPtr ( LinkedList  list,
const void *  element 
)

Insert an item at the end of a LinkedList.

Parameters
listThe LinkedList you want to append an item to
elementPointer to the item you want to append to list

◆ areLLEqual()

byte areLLEqual ( const LinkedList  list1,
const LinkedList  list2 
)

Compare two LinkedList.

Parameters
list1The first LinkedList you want to compare
list2The second LinkedList you want to compare
Returns
The result of the comparison
Return values
TRUElist1 and list2 have equal type, equal length and equal contents
FALSElist1 and list2 do not have equal type, equal length or equal contents

◆ chooseNewLLFromArray()

LinkedList chooseNewLLFromArray ( const spec_t  spec,
const void *  arr,
unsigned int  size 
)

Create a LinkedList from an array.

Parameters
specThe type specifier of the array passed. Refer to spec_t for supported types
arrThe array you want to create the LinkedList from
sizeThe number of items of list
Returns
A LinkedList containing the elements in list in the same order

◆ deleteLL()

void deleteLL ( LinkedList  list)

Delete a LinkedList.

Parameters
listThe LinkedList you want to delete

◆ getFromLL()

void getFromLL ( LinkedList  list,
unsigned int  index,
void *  dest 
)

Get an item from a LinkedList.

Parameters
listThe LinkedList you want to get an item from
indexThe index of the item you want to get
destThe address of the variable you want to store the item in

◆ getLLLength()

unsigned int getLLLength ( const LinkedList  list)

Get the size of a LinkedList.

Parameters
listThe LinkedList you want to evaluate
Returns
The number of elements in list

◆ insertToLL()

void insertToLL ( LinkedList  list,
unsigned int  index,
  ... 
)

Insert an element at a specified position of a LinkedList.

Parameters
listThe LinkedList you want to insert an element into
indexThe position you want to insert an element at
...The item you want to insert into list
Note
Even though inserting more than one item for single call does not throw a compiler nor runtime error, only inserting one item is supported. Other items are ignored and are not inserted into list. If you don't specify any item to be inserted, still no errors occur but the content of your LinkedList can be messed up

◆ isInLL()

byte isInLL ( LinkedList  list,
  ... 
)

Detect if an element is inside a LinkedList.

Parameters
listThe LinkedList you want search in
...The element you want to search
Note
Even though checking more than one item for single call does not throw a compiler nor runtime error, only checking one item is supported. Other items are ignored. If you don't specify any item to be checked, still no errors occur but the return value of the function can be unpredictable
Return values
TRUEGiven element is contained in list
FALSEGiven element is not contained in list

◆ isLLEmpty()

byte isLLEmpty ( LinkedList  list)

Check if LinkedList is empty.

Parameters
listThe LinkedList to be checked
Return values
TRUElist is empty
FALSElist is not empty

◆ linearSearchLL()

int linearSearchLL ( LinkedList  list,
  ... 
)

Linear search for LinkedList.

Parameters
listThe LinkedList to be inspected
...The key to be searched
Note
This function does not support float and double LinkedList types
Even though passing more than one key 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
Returns
The index of the first occurence of the key in the list or the return code of the function
Return values
KEY_NOT_FOUNDThe key was not found

◆ linearSearchLLPtr()

void * linearSearchLLPtr ( LinkedList  list,
  ... 
)

Linear search for LinkedList.

Parameters
listThe LinkedList to be inspected
...The key to be searched
Note
This function does not support float and double LinkedList types
Even though passing more than one key 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
Returns
A void pointer of the first occurence of the key in the list or the return code of the function
Return values
NULLThe key was not found

◆ mergeLL()

void mergeLL ( LinkedList  list1,
const LinkedList  list2 
)

Merge two LinkedList.

Parameters
list1The first LinkedList to be merged, where the merged LinkedList is saved
list2The second LinkedList to be merged

◆ newLL()

LinkedList newLL ( const spec_t  spec)

Allocate a new LinkedList of specified type.

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

◆ newLLFromCharArray()

LinkedList newLLFromCharArray ( const char  arr[],
unsigned int  size 
)

Create a LinkedList from a array of chars.

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

◆ newLLFromDoubleArray()

LinkedList newLLFromDoubleArray ( const double  arr[],
unsigned int  size 
)

Create a LinkedList from an array of doubles.

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

◆ newLLFromFloatArray()

LinkedList newLLFromFloatArray ( const float  arr[],
unsigned int  size 
)

Create a LinkedList from a array of floats.

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

◆ newLLFromIntArray()

LinkedList newLLFromIntArray ( const int  arr[],
unsigned int  size 
)

Create a LinkedList from a array of ints.

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

◆ newLLFromLL()

LinkedList newLLFromLL ( const LinkedList  list)

Get a copy of a LinkedList.

Parameters
listThe LinkedList you want to copy
Returns
A copy of list

◆ newLLFromPtrArray()

LinkedList newLLFromPtrArray ( const void *  arr,
unsigned int  size 
)

Create a LinkedList from an array of pointers.

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

◆ printLL()

void printLL ( const spec_t  spec,
const LinkedList  list 
)

Print contents from a LinkedList.

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

◆ removeFromLL()

void removeFromLL ( LinkedList  list,
unsigned int  index 
)

Remove an item from a LinkedList.

Parameters
listThe LinkedList you want to delete an item from
indexThe index of the item you want to delete

◆ setLLItem()

void setLLItem ( LinkedList  list,
unsigned int  index,
  ... 
)

Set value of an element of a LinkedList.

Parameters
listThe LinkedList you want to edit
indexThe index of the element you want to change
...The item you want to set the index-th element of list to
Note
Even though changing more than one item for single call does not throw a compiler nor runtime error, only setting one item is supported. Other items are ignored. If you don't specify any item to be inserted, still no errors occur but the content of your LinkedList can be messed up

◆ sliceLL()

void sliceLL ( LinkedList  list,
unsigned int  begin,
unsigned int  end 
)

Slice a LinkedList.

Parameters
listThe LinkedList you want to slice, where the sliced LinkedList is saved
beginThe index of the beginning of the slice
endThe index of the end of the slice