Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. package tri;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Arrays;
  5.  
  6. public class TestTri {
  7.  
  8. public static void main (String args[]) {
  9.  
  10. //Tableau a trier
  11. Pays[] array = new Pays[10];
  12. array[0] = new Pays("Uruguay", 176220);
  13. array[1] = new Pays("thailand", 514000);
  14. array[2] = new Pays("Belgium", 30510);
  15. array[3] = new Pays("Argentina", 2766890);
  16. array[4] = new Pays("Canada", 9984670);
  17. array[5] = new Pays("France", 643427);
  18. array[6] = new Pays("Chile", 756950);
  19. array[7] = new Pays("Denmark", 43094);
  20. array[8] = new Pays("Estonia", 45226);
  21. array[9] = new Pays("Germany", 357021);
  22.  
  23. //déclaration de la variable de calcul du temps
  24. long startTime;
  25. long estimatedTime;
  26.  
  27. //déclaration des variables pour le choix du tri
  28. Scanner sc = new Scanner(System.in);
  29. int choixTri = 6;
  30.  
  31. //boucle générale du test
  32. boolean quit = false;
  33. while(quit == false) {
  34.  
  35. //boucle pour le choix du tri
  36. while(choixTri > 5) {
  37. System.out.println("1 : Tri par séléction");
  38. System.out.println("2 : Tri par insertion");
  39. System.out.println("3 : Tri rapide");
  40. System.out.println("4 : Tri rapide 2");
  41. System.out.println("5 : Quitter");
  42.  
  43.  
  44. System.out.println("Sélection du numéro du tri à tester :");
  45. choixTri = sc.nextInt();
  46. }
  47.  
  48. if(choixTri == 1) {
  49. System.out.println("Choix 1 : Tri par séléction");
  50. TriParSelection tri = new TriParSelection(array);
  51. startTime = System.currentTimeMillis();
  52. tri.trier();
  53. System.out.println(Arrays.toString(array));
  54. estimatedTime = System.currentTimeMillis() - startTime;
  55. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  56. }
  57.  
  58. else if(choixTri == 2) {
  59. System.out.println("Choix 2 : Tri par insertion");
  60. TriParInsertion tri = new TriParInsertion(array);
  61. startTime = System.currentTimeMillis();
  62. tri.trier();
  63. System.out.println(Arrays.toString(array));
  64. estimatedTime = System.currentTimeMillis() - startTime;
  65. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  66. }
  67.  
  68. else if(choixTri == 3) {
  69. System.out.println("Choix 3 : Tri rapide");
  70. QuickSorter tri = new QuickSorter(array);
  71. startTime = System.currentTimeMillis();
  72. tri.trier();
  73. System.out.println(Arrays.toString(array));
  74. estimatedTime = System.currentTimeMillis() - startTime;
  75. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  76. }
  77.  
  78. else if(choixTri == 4) {
  79. System.out.println("CHoix 4 : Tri rapide 2");
  80. QuickSorter2 tri = new QuickSorter2(array);
  81. startTime = System.currentTimeMillis();
  82. tri.trier();
  83. System.out.println(Arrays.toString(array));
  84. estimatedTime = System.currentTimeMillis() - startTime;
  85. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  86. }
  87.  
  88. else if(choixTri == 5) {
  89. System.out.println("Choix 5 : Quitter");
  90. QuickSorter2 tri = new QuickSorter2(array);
  91. quit = true;
  92. }
  93.  
  94. else {
  95. System.out.println("\n Erreur, veuillez réessayer \n");
  96. }
  97.  
  98. //réinitialisation du choix
  99. choixTri = 6;
  100.  
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement