rendre une fonction plus générique
Bonjour,
J'ai pour le moment 2 fonctions quasi identique et je voulais savoir comment les fusionner?
fonction 1
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| /*
tri un stucture index ouvrier
DEMANDE adresse struct index ouvrier, Max ouvriers
*/
void tri(struct indexouvrier* Index, int size)
{
short i = 0, j = 0;
struct indexouvrier tmp;
for (i = 0; i < size; i++)
for (j = i; j < size && strcmp((Index + i)->Nom, "-1") != 0 && strcmp((Index + j)->Nom, "-1") != 0; j++)
if (strcmp((Index + i)->Nom, (Index + j)->Nom) > 0 && strcmp((Index + j)->Nom, "-1") != 0) {
/*intervertir les 2 structures*/
tmp = Index[i];
Index[i] = Index[j];
Index[j] = tmp;
}
} |
fonction 2
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| /*
tri un stucture index chantier
DEMANDE adresse struct index chantier, Max chantiers
*/
void tri(struct indexchantier* Index, int size)
{
short i = 0, j = 0;
struct indexchantier tmp;
for (i = 0; i < size; i++)
for (j = i; j < size && strcmp((Index + i)->Nom, "-1") != 0 && strcmp((Index + j)->Nom, "-1") != 0; j++)
if (strcmp((Index + i)->Nom, (Index + j)->Nom) > 0 && strcmp((Index + j)->Nom, "-1") != 0) {
/*intervertir les 2 structures*/
tmp = Index[i];
Index[i] = Index[j];
Index[j] = tmp;
}
} |
la seul chose qui change c'est la définition de structure l'une est faite pour un index chantier et l'autre pour un index ouvrier.
Size représente la taille du tableau de structure index respectif
Merci d'avance pour votre aide