Implementation of a linked list.
More...
Go to the source code of this file.
|
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...
|
|
Implementation of a linked list.
- Author
- Rui Carlos Gonçalves
- Version
- 3.0.1
- Date
- 01/2014
Definition in file list.c.
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
-
list | the list |
index | the index of the element to be provided |
value | pointer 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
-
list | the 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
-
list | the list |
value | pointer 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
-
list | the list |
index | the index at which the new value is to be inserted |
value | the 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
-
list | the list |
value | the 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
-
list | the list |
value | the 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.
Creates an iterator from a list.
- See Also
- Iterator
- Parameters
-
- 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
-
list | the list |
value | pointer 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
-
list | the list |
fun | the 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
-
list | the list. |
index | the index of the element to be removed |
value | pointer 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
-
list | the list. |
value | pointer 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
-
list | the list. |
value | pointer 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
-
- Returns
- the size of the list
Definition at line 298 of file list.c.
Creates a list.
- Returns
NULL
if an error occurred
the new list otherwise
Definition at line 13 of file list.c.