Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tp2;
  7.  
  8. import java.util.ArrayList;
  9. import java.lang.String;
  10.  
  11. /**
  12. *
  13. * @author francis
  14. */
  15. public class SortedListOfStrings extends ArrayList{
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public SortedListOfStrings(){
  21. super();
  22. }
  23.  
  24. public void add(String chaine){
  25. if (this.isEmpty())
  26. add( 0, chaine);
  27. if (this.contains(chaine) != true){
  28. int i = 0;
  29. String objet_courant = (String) this.get(i);
  30.  
  31. while(i != this.size() && chaine.compareTo(objet_courant) < 0){
  32. objet_courant = (String) this.get(i);
  33. i++;
  34. }
  35. add( i, chaine);
  36. }
  37. }
  38. public static void main(String[] args) {
  39. // TODO code application logic here
  40. String ch0 = "z";
  41. String ch1 = "a";
  42. String ch2 = "c";
  43. String ch3 = "e";
  44. String ch4 = "f";
  45.  
  46. SortedListOfStrings chaine_triée = new SortedListOfStrings();
  47.  
  48. chaine_triée.add(ch0);
  49. chaine_triée.add(ch1);
  50. /*chaine_triée.add(ch2);
  51. chaine_triée.add(ch3);
  52. chaine_triée.add(ch4);*/
  53.  
  54. for (int i = 0; i < chaine_triée.size(); i++){
  55. System.out.println(chaine_triée.get(i));
  56. }
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement