Bonjour,
je chaerche un astuce pour effectuer un tri sur un tableau à 2 dimensions ...
J'ai bien un bout de code, mais je ne vois pas comment trier sur un élément du tableau .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
#include "winproc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef char * Pchar;
typedef int (* TFcmp) (const void *p1, const void *p2) ;
char tmp[8];
int cmpMot( const void * m1, const void * m2);
int cmpEntier( const void * pm1, const void * pm2);
 
void essai_tri (HWND hwnd) {
	struct { int dt;
	int mt; } ti[] = { 17, 25, 21, 25, 19, 23};
int i;
int nti = sizeof(ti)/sizeof(ti[0]);
MessageBox(hwnd, itoa(nti,tmp,10), "Taille", MB_OK|MB_ICONEXCLAMATION);
 
for (i=0; i<nti; i++) 
MessageBox(hwnd, itoa(ti[i].dt,tmp,10), "Avant Tri", MB_OK|MB_ICONEXCLAMATION);
 
qsort( ti, nti, sizeof(int), cmpEntier);
 
for (i=0; i<nti; i++)
MessageBox(hwnd, itoa(ti[i].dt,tmp,10), "Après Tri", MB_OK|MB_ICONEXCLAMATION);
 
}
/*------------------------------------------------------------------*/
/*                  TRI du Tableau Ordre CROISSANT                  */
/*------------------------------------------------------------------*/
int cmpEntier( const void * p1, const void * p2) {
typedef const int * PEntierConstant;
  PEntierConstant pi1 = (PEntierConstant)p1,
  pi2 = (PEntierConstant)p2;
  return *pi1 - *pi2 ;
}