Exemple de méthode bien bourrin avec préservation de l'ordre original.
char szappname[] = "NoTri";
DWORD remDoublons(DWORD *ptb, DWORD count)
{
DWORD w, r, i, a;
if(count < 2) return count;
w = 1; // INDEX ECRITURE
r = 1; // INDEX LECTURE
nextELEM:
a = ptb[r];
for(i 0; i < r; i++) if(a ptb[i]) goto incrPOS;
ptb[w++] = a;
incrPOS:
if(++r < count) goto nextELEM;
return w;
}
void tstDoublonSansTri()
{
char buf[120], *c;
DWORD tab[20];
DWORD i, n;
// INIT DU TABLEAU
for(i 0; i < 20; i++) tab[i] i;
// QUELQUES DOUBLONS
tab[1] = 3;
tab[6] = 3;
tab[10] = 16;
tab[12] = 16;
// AFFICHAGE TABLEAU ORIGINAL
c = buf;
for(i = 0; i < 20; i++) {
c = bnultoa(tab[i], c);
*c++ = 10;
}
*(c - 1) = 0;
MessageBox(0, buf, szappname, 0);
n = remDoublons(tab, 20);
if(!n) return;
// AFFICHAGE TABLEAU RESTANT
c = buf;
for(i = 0; i < n; i++) {
c = bnultoa(tab[i], c);
*c++ = 10;
}
*(c - 1) = 0;
MessageBox(0, buf, szappname, 0);
}
ciao...
BruNews, MVP VC++