Je rage : J'arrive pas a trier un tableau...

Je rage : J'arrive pas a trier un tableau... - Java - Programmation

Marsh Posté le 13-11-2005 à 00:07:19    

Voila ce que j'ai fais mais ca fonctionne pas (pour un tableau de 10 entiers) :
 
for (int j = 0; j < (tab.length -1); j++)
{
 for (int i = indMin; i < (tab.length -1); i++)
 {
  if (tab[i] < tab[indMin])
  {
   min = tab[i];
   j = i;
  }
 interm = tab[indMin];
 tab[j] = min;
 tab[indMin] = interm;
 indMin = indMin + 1;
 }
}
 
Quelqu'un verrait-il mon erreur ?
 
Merci d'avance...

Reply

Marsh Posté le 13-11-2005 à 00:07:19   

Reply

Marsh Posté le 13-11-2005 à 01:01:21    

Arrays.sort ça va pas [:petrus dei]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 13-11-2005 à 01:04:23    

kolbek a écrit :

Voila ce que j'ai fais mais ca fonctionne pas (pour un tableau de 10 entiers) :
 
for (int j = 0; j < (tab.length -1); j++)
{
 for (int i = indMin; i < (tab.length -1); i++)
 {
  if (tab[i] < tab[indMin])
  {
   min = tab[i];
   j = i;
  }
 interm = tab[indMin];
 tab[j] = min;
 tab[indMin] = interm;
 indMin = indMin + 1;
 }
}
 
Quelqu'un verrait-il mon erreur ?
 
Merci d'avance...


 
A priori j'aurais mis tab.length à la place de (tab.length -1), sinon tu oublies le dernier element du tableau.
 
Ensuite ta permutation me semble bizzare, il s'agit bien d'un tri par insertion?
indMin n'est pas initialisé. Je capte pas le j=i non plus, ca fait faire n'importe quoi à ta boucle.
 
Pour une solution (merki google): http://www.dailly.info/algorithmes [...] ertion.php

Reply

Marsh Posté le 13-11-2005 à 01:08:20    


http://en.wikipedia.org/wiki/Insertion_sort
http://en.wikipedia.org/wiki/Bubble_sort
http://en.wikipedia.org/wiki/Quicksort
http://en.wikipedia.org/wiki/Heapsort
http://en.wikipedia.org/wiki/Merge_sort
 
:o


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 13-11-2005 à 01:38:33    

pouah tout ça c'est compliqué :) rien de plus simple que le tri par minimum / maximum :)

Reply

Marsh Posté le 13-11-2005 à 02:17:43    

kolbek a écrit :

Voila ce que j'ai fais mais ca fonctionne pas (pour un tableau de 10 entiers) :
Quelqu'un verrait-il mon erreur ?
Merci d'avance...

Code :
  1. for (int j = 0; j < (tab.length -1); j++)
  2. {
  3. for (int i = indMin; i < (tab.length -1); i++)
  4. {
  5.  if (tab[i] < tab[indMin])
  6.  {
  7.   min = tab[i];
  8.   j = i;
  9.  }
  10.         // soit il te manque un crochet là,
  11. interm = tab[indMin];    // (en plus = interm 2 lignes plus bas sans que ca change au mileu)
  12. tab[j] = min;               // soit tab[j] déja egal à tab [i]
  13. tab[indMin] = interm;
  14. indMin = indMin + 1;
  15. }
  16. }

Bref tu ne change jamais la valeur de quoi que ce soit [:spamafote]


---------------
The Rom's, à votre service
Reply

Marsh Posté le 13-11-2005 à 09:45:51    

merci beaucoup

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed