Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 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. // choix du tri
  36. System.out.println("1 : Tri par séléction");
  37. System.out.println("2 : Tri par insertion");
  38. System.out.println("3 : Tri rapide");
  39. System.out.println("4 : Tri rapide 2");
  40. System.out.println("5 : Quitter");
  41.  
  42.  
  43. System.out.println("Sélection du numéro du tri à tester :");
  44. choixTri = sc.nextInt();
  45.  
  46. if(choixTri == 1) {
  47. System.out.println("Choix 1 : Tri par séléction");
  48. TriParSelection tri = new TriParSelection(array);
  49. startTime = System.currentTimeMillis();
  50. tri.trier();
  51. System.out.println(Arrays.toString(array));
  52. estimatedTime = System.currentTimeMillis() - startTime;
  53. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  54. }
  55.  
  56. else if(choixTri == 2) {
  57. System.out.println("Choix 2 : Tri par insertion");
  58. TriParInsertion tri = new TriParInsertion(array);
  59. startTime = System.currentTimeMillis();
  60. tri.trier();
  61. System.out.println(Arrays.toString(array));
  62. estimatedTime = System.currentTimeMillis() - startTime;
  63. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  64. }
  65.  
  66. else if(choixTri == 3) {
  67. System.out.println("Choix 3 : Tri rapide");
  68. QuickSorter tri = new QuickSorter(array);
  69. startTime = System.currentTimeMillis();
  70. tri.trier();
  71. System.out.println(Arrays.toString(array));
  72. estimatedTime = System.currentTimeMillis() - startTime;
  73. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  74. }
  75.  
  76. else if(choixTri == 4) {
  77. System.out.println("CHoix 4 : Tri rapide 2");
  78. QuickSorter2 tri = new QuickSorter2(array);
  79. startTime = System.currentTimeMillis();
  80. tri.trier();
  81. System.out.println(Arrays.toString(array));
  82. estimatedTime = System.currentTimeMillis() - startTime;
  83. System.out.println("\n Le tri du tableau a été effectué en " +estimatedTime +" ms \n");
  84. }
  85.  
  86. else if(choixTri == 5) {
  87. System.out.println("Choix 5 : Quitter");
  88. QuickSorter2 tri = new QuickSorter2(array);
  89. quit = true;
  90. }
  91.  
  92. else {
  93. System.out.println("\n Erreur, veuillez réessayer \n");
  94. }
  95.  
  96. }
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement