3 private int int_array
[];
4 private int array_size
;
5 private int current_size
;
7 private void setSize(int size
) {
11 private int getSize() {
15 private void setCurrentSize(int index
) {
19 private int getCurrentSize() {
24 int_array
= new int[size
];
29 public boolean inserer(int value
) {
31 System
.out
.println("Tableau plein");
34 //FIXME: Avoid duplicated values
36 for (i
= getCurrentSize() - 1; (i
>= 0 && int_array
[i
] > value
); i
--) {
37 int_array
[i
+ 1] = int_array
[i
];
39 int_array
[i
+ 1] = value
;
44 private int binarySearch(int first
, int last
, int value
) {
47 int middle
= (first
+ last
) / 2;
48 if (value
== int_array
[middle
])
50 if (value
> int_array
[middle
])
51 return binarySearch((middle
+ 1), last
, value
);
52 return binarySearch(first
, (middle
-1), value
);
55 public boolean supprimer(int value
) {
57 System
.out
.println("Aucune valeur à supprimer");
61 // Find position of element to be deleted
62 int pos
= binarySearch(0, getCurrentSize(), value
);
66 System
.out
.println("Valeur à supprimer inexistante");
71 for (int i
= pos
; i
< getCurrentSize() - 1; i
++) {
72 int_array
[i
] = int_array
[i
+ 1];
79 private boolean is_full() {
80 return (getCurrentSize() >= getSize());
83 private boolean is_empty() {
84 return (getCurrentSize() == 0);
87 public void afficher() {
88 for (int i
= 0; i
< getSize(); i
++) {
89 System
.out
.println("element " + i
+ " " + int_array
[i
]);
93 public static void main(String
[] args
) {
94 Entiers integer
= new Entiers(5);
114 integer
.supprimer(12);
117 System
.out
.println("Current size " + integer
.getCurrentSize());
119 integer
.supprimer(1);
122 System
.out
.println("Current size " + integer
.getCurrentSize());