Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

list.c File Reference

Go to the source code of this file.

Functions

void list_init (List *liste, void(*detruire)(void *donnee), int(*corresp)(const void *val1, const void *val2))
 Initialize the linked list. This function should be called first.

void list_destroy (List *liste)
 Destroy the linked list. This function free all allocated memory used by the list.

int list_ins_next (List *liste, ListElmt *element, const void *donnee)
 Insert a new element into the linked list.

int list_rem_next (List *liste, ListElmt *element, void **donnee)
 Remove an element from the linked list.

ListElmtlist_find (List *liste, ListElmt *from, void *data, ListElmt **prec)
 Search an element into the linked list.


Detailed Description

This code implements linked lists.

Definition in file list.c.


Function Documentation

void list_destroy List   liste
 

Destroy the linked list. This function free all allocated memory used by the list.

Parameters:
liste Pointer to a linked list structure (that you need to destroy).
Examples:
test_list.c.

Definition at line 40 of file list.c.

References List_::detruire, list_rem_next(), and list_size.

Referenced by chtbl_destroy().

ListElmt* list_find List   liste,
ListElmt   from,
void *    data,
ListElmt **    prec
 

Search an element into the linked list.

Parameters:
liste Pointer to the linked list structure.
from Pointer to the linked list's element where the search begins. If 'point' in NULL, then the search begins at the beginning of the linked list.
data Pointer to a data a user defined structure that contains the data to search for.
prec Pointer to a pointer that will receive the address of the element before the found element.
Returns:
  • If the function finds an element that matches data, then it returns a pointer to this element. In this case, prec points to the previous element (unless the found element was the first element in the linked list ... in this the value of prec is NULL).
  • If there is no element that matches data, then the function returns NULL.
Examples:
test_list.c.

Definition at line 231 of file list.c.

References List_::corresp, list_data, list_head, and list_next.

Referenced by chtbl_remove().

void list_init List   liste,
void(*    detruire)(void *donnee),
int(*    corresp)(const void *val1, const void *val2)
 

Initialize the linked list. This function should be called first.

Parameters:
liste Pointer to a linked list structure (that will be initialized).
detruire Pointer to a function that will be called to free the memory used to store one link of the list. Please note that:
  • This function depends on the type of data stored into the linked list.
  • detruire could be a NULL pointer (if user's data are not dtnamically allocated).
corresp Pointer to a function that will be called to compare to elements. Please note that this function depends on the type of data stored into the linked list. The function must returns 1 if the elements' datas are identical; 0 otherwise.
Examples:
test_list.c.

Definition at line 21 of file list.c.

References List_::corresp, List_::detruire, List_::queue, List_::taille, and List_::tete.

Referenced by chtbl_init().

int list_ins_next List   liste,
ListElmt   element,
const void *    donnee
 

Insert a new element into the linked list.

Parameters:
liste Pointer to a linked list structure.
element Pointer to an (existing) element of the linked list. The new element will be inserted AFTER the element pointed by element.
donnee Pointer to the data to insert. Please note that the data is NOT copied into the linked list.
Returns:
Upon successful completion the function return the value 0. Otherwise the function returns -1.
Warning:
The inserted data is NOT copied into the linked list! Therefore you should not free it unless you know exactly what you are doing.
Examples:
test_list.c.

Definition at line 69 of file list.c.

References ListElmt_::donnee, list_size, List_::queue, ListElmt_::suivant, List_::taille, and List_::tete.

Referenced by chtbl_insert(), and stack_push().

int list_rem_next List   liste,
ListElmt   element,
void **    donnee
 

Remove an element from the linked list.

Parameters:
liste Pointer to a linked list structure.
element Pointer to an (existing) element of the linked list. The element to delete is the element AFTER the element pointed by element. If you want to remove the first element of the list, then you must specify NULL as second argument for the function list_rem_next().
donnee Pointer that vill point to the data stored by the removed element.
Returns:
Upon successful completion the function return the value 0. Otherwise the function returns -1.
Warning:
This function does NOT free the element's data (it only frees the element's structure). Therefore you should use donnee to free the element's data yourself.
Examples:
test_list.c.

Definition at line 145 of file list.c.

References ListElmt_::donnee, list_size, List_::queue, ListElmt_::suivant, List_::taille, and List_::tete.

Referenced by chtbl_remove(), list_destroy(), and stack_pop().


Generated on Thu Apr 3 16:23:46 2003 for Common_C_libraries by doxygen1.3-rc1