Mathc initiation/Fichiers h : x 17a2
Apparence
Installer ce fichier dans votre répertoire de travail.
xset.h utilitaire |
---|
/* ------------------------------------ */
/* Save as : xset.h */
/* ------------------------------------ */
void create_SetI(
Set *set)
{
set->size = 0;
set->head = NULL;
}
/* ------------------------------------ */
int member_EI(
Set *set,
int data_new)
{
Element *element_n;
if( set_size(set) ) /* if the set is not empty */
{
element_n=set_head(set);
do
{
if(data_new==element_data(element_n))return(1);
}
while((element_n=element_next(element_n)));
}
return(0); /* set empty or new member */
}
/* ------------------------------------ */
void insert_EI(
Set *set,
int data_new)
{
Element *element_new;
if(!(member_EI(set,data_new))) /* set empty or new member */
{
if((element_new=(Element *)malloc(sizeof(Element))) == NULL) exit(1);
element_new->data = data_new;
element_new->next = set->head;
set->head = element_new;
set->size++;
}
}
/* ------------------------------------ */
int erase_prev_EI(
Set *set,
Element *element
)
{
Element *element_old;
if( set_size(set) )
{
if(element == NULL)
{
element_old = set->head;
set->head = set->head->next;
}
else
{
element_old = element->next;
element->next = element->next->next;
}
free(element_old);
set->size--;
}
return 0;
}
/* ------------------------------------ */
void erase_EI(
Set *set,
int data)
{
Element *element_n;
Element *element_prev_n;
int size = set_size(set);
if( set_size(set) )
{
element_prev_n = NULL;
element_n = set_head(set);
do{
if( data==element_data(element_n)) break;
element_prev_n = element_n;
size--;
}
while((element_n=element_next(element_n)));
if(!(element_n==NULL)) erase_prev_EI(set,element_prev_n);
}
}
/* ------------------------------------ */
void erase_SetI(
Set *set)
{
Element *element_old;
while(set_size(set)>0)
{
element_old = set->head;
set->head = set->head->next;
free(element_old);
set->size--;
}
}
Les noms des fonctions me semblent bien explicites. Si vous voulez étudier le code, il faudra commencer par étudier les listes en langage C. Cette librairie est juste présentée pour vous montrer des exemples d'applications mathématiques en langage C.