Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1026 connectés 

  FORUM HardWare.fr
  Programmation
  Java

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

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

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

n°1244497
kolbek
Posté le 13-11-2005 à 00:07:19  profilanswer
 

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...

mood
Publicité
Posté le 13-11-2005 à 00:07:19  profilanswer
 

n°1244512
masklinn
í dag viðrar vel til loftárása
Posté le 13-11-2005 à 01:01:21  profilanswer
 

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
n°1244513
philippe06
Posté le 13-11-2005 à 01:04:23  profilanswer
 

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

n°1244514
masklinn
í dag viðrar vel til loftárása
Posté le 13-11-2005 à 01:08:20  profilanswer
 


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
n°1244515
Taz
bisounours-codeur
Posté le 13-11-2005 à 01:38:33  profilanswer
 

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

n°1244519
TheRom_S
Posté le 13-11-2005 à 02:17:43  profilanswer
 

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
n°1244529
kolbek
Posté le 13-11-2005 à 09:45:51  profilanswer
 

merci beaucoup


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

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

 

Sujets relatifs
Dim d'un tableau[RESOLU]Sélection d'un tableau Word
[Delphi] tableau et pointeuroverflow: auto et tableau
copier dans une case d'un tableau d'entier 4 bytesRécupérer la taille d'un tableau associatif
Coment écrire dans une case d'un tableau [Résolu ]trier plusieurs tableau de mem dimension avec un unique ?
Trier un tableau par date ... 
Plus de sujets relatifs à : Je rage : J'arrive pas a trier un tableau...


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)