LibRCG  3.1.1
list.h File Reference

Implementation of a linked list. More...

Go to the source code of this file.

Data Structures

struct  SListNode
 Linked list node structure. More...
 
struct  SList
 Linked list structure. More...
 

Typedefs

typedef SListNodeListNode
 Linked list node definition. More...
 
typedef SListList
 Linked list definition. More...
 

Functions

List newList (void)
 Creates a list. More...
 
void listDelete (List list)
 Deletes a list. More...
 
int listInsertFst (List list, void *value)
 Inserts an element at the beginning of a list. More...
 
int listInsertLst (List list, void *value)
 Inserts an element at the end of a list. More...
 
int listInsertAt (List list, int index, void *value)
 Inserts an new element at the specified position of a list. More...
 
int listRemoveFst (List list, void **value)
 Removes the first element of a list. More...
 
int listRemoveLst (List list, void **value)
 Removes the last element of a list. More...
 
int listRemoveAt (List list, int index, void **value)
 Removes the element at the specified position of a list. More...
 
int listFst (List list, void **value)
 Provides the value at the first position of a list. More...
 
int listLst (List list, void **value)
 Provides the value at the last position of a list. More...
 
int listAt (List list, int index, void **value)
 Provides the element at the specified position of a list. More...
 
int listSize (List list)
 Returns the size of a list. More...
 
int listMap (List list, void(*fun)(void *))
 Applies a function to the elements of a list. More...
 
Iterator listIterator (List list)
 Creates an iterator from a list. More...
 

Detailed Description

Implementation of a linked list.

Provides functions to create and manipulate a linked list.

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

Definition in file list.h.

Typedef Documentation

typedef SList* List

Linked list definition.

Definition at line 50 of file list.h.

typedef SListNode* ListNode

Linked list node definition.

Definition at line 32 of file list.h.

Function Documentation

int listAt ( List  list,
int  index,
void **  value 
)

Provides the element at the specified position of a list.

If there is no element at the specified position, it will be put the value NULL at value.

Attention
This function puts at value a pointer to the value at the last position. Changes to this value will affect the element in the list.
Parameters
listthe list
indexthe index of the element to be provided
valuepointer where the value at the specified position will be put
Returns
0 if there was an elements at the specified position
1 otherwise

Definition at line 278 of file list.c.

void listDelete ( List  list)

Deletes a list.

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

Definition at line 27 of file list.c.

int listFst ( List  list,
void **  value 
)

Provides the value at the first position of a list.

If the list 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
listthe list
valuepointer where the value at the first position will be put
Returns
0 if the list was not empty
1 otherwise

Definition at line 250 of file list.c.

int listInsertAt ( List  list,
int  index,
void *  value 
)

Inserts an new element at the specified position of a list.

The position, specified by argument index, must be a non negative integer, and less than the current size of the list.

Parameters
listthe list
indexthe index at which the new value is to be inserted
valuethe value to be inserted
Returns
0 if the new value was inserted
1 if the position was not valid
2 if it was not possible to insert the new element

Definition at line 116 of file list.c.

int listInsertFst ( List  list,
void *  value 
)

Inserts an element at the beginning of a list.

Parameters
listthe list
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 42 of file list.c.

int listInsertLst ( List  list,
void *  value 
)

Inserts an element at the end of a list.

Parameters
listthe list
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 79 of file list.c.

Iterator listIterator ( List  list)

Creates an iterator from a list.

See Also
Iterator
Parameters
listthe list
Returns
NULL if an error occurred
the iterator otherwise

Definition at line 320 of file list.c.

int listLst ( List  list,
void **  value 
)

Provides the value at the last position of a list.

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

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

Definition at line 264 of file list.c.

int listMap ( List  list,
void(*)(void *)  fun 
)

Applies a function to the elements of a list.

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

Parameters
listthe list
funthe function to be applied
Returns
0 if the list was not empty
1 otherwise

Definition at line 305 of file list.c.

int listRemoveAt ( List  list,
int  index,
void **  value 
)

Removes the element at the specified position of a list.

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
listthe list.
indexthe index of the element to be removed
valuepointer where the removed value should be put (or NULL)
Returns
0 if the element was removed
1 if the value of index was invalid

Definition at line 220 of file list.c.

int listRemoveFst ( List  list,
void **  value 
)

Removes the first element of a list.

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
listthe list.
valuepointer where the removed value should be put (or NULL)
Returns
0 if the element was removed
1 if the list was empty

Definition at line 158 of file list.c.

int listRemoveLst ( List  list,
void **  value 
)

Removes the last element of a list.

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
listthe list.
valuepointer where the removed value should be put (or NULL)
Returns
0 if the element was removed
1 if the list was empty

Definition at line 189 of file list.c.

int listSize ( List  list)

Returns the size of a list.

Parameters
listthe list
Returns
the size of the list

Definition at line 298 of file list.c.

List newList ( void  )

Creates a list.

Returns
NULL if an error occurred
the new list otherwise

Definition at line 13 of file list.c.

LibRCG © 2004-2015   Rui Carlos Gonçalves