Bonjour,
je débute sur le c# et java donc je m'entraine a faire des petites manipulations d'algo basiques et voila mon problème j'écris un algo de tri a bulle en java il fonctionne je réécris la même structure en c# et il ne veut pas s'afficher.
Si j'utilise la fonction comme ceci isplayArray(arrayNonTrie); sans utiliser la méthode tableBubble() j'ai bien un tableau de 10 chiffres qui s'affiche dans la console mais des que je passe par ma méthod de trie et que j'appel a nouveau mon tableau après l'avoir trié bien rien ne s'affiche
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { //Method pour afficher en console un tableau d'entier static void displayArray(int[] Array) { for (int i = 0; i < Array.Length; i++) { Console.WriteLine(Array[i]); } return; } //methode pour trier un tableau d'entier via Tri a bulle static int[] tableBubble(int[] array) { //booleen pour sortir du tant que Boolean noEchange = true; do { for (int j = 0; j < array.Length-1; j++) { if (array[j] > array[j + 1]) { int tmp = array[j]; array[j] = array[j + 1]; array[j + 1] = tmp; noEchange = false; } } } while (!noEchange); //retour du tableau trié return array; } static void Main(string[] args) { //Instanciation de rndNumber de type random Random rndNumber = new Random(); //Déclaration d'un tableau unidimensionnel int[] arrayNonTrie = new int[10]; //remplissage du tableau arrayNonTrie de chiffres aléatoire for (int i = 0; i < arrayNonTrie.Length; i++) { int numberRnd = rndNumber.Next(1, 100); arrayNonTrie[i] = numberRnd; } //displayArray(arrayNonTrie); //appel de la method tableBubble pour trier le tableau arrayNonTrie tableBubble(arrayNonTrie); //appel de la method displayarray pour afficher le tableau arraynontrier qui est trie displayArray(arrayNonTrie); }
merci d'avance
Partager