2 class Entiers
extends Structure
{
3 private int[] int_array
;
4 private int array_size
;
5 private int current_size
;
7 public void setSize(int size
) {
11 public int getSize() {
15 public void setCurrentSize(int index
) {
19 public int getCurrentSize() {
24 int_array
= new int[size
];
29 public boolean inserer(int value
) {
31 System
.out
.println("Tableau plein");
39 for (int i
= 0; i
< getCurrentSize(); i
++) {
40 if (int_array
[i
] == value
) {
42 } else if (int_array
[i
] > value
) {
43 for (int j
= getCurrentSize(); j
> i
; j
--) {
44 int_array
[j
] = int_array
[j
- 1];
53 * The current value to add is > to all elements in the tab.
54 * So add it at the end.
56 int_array
[getCurrentSize()] = value
;
61 private int binarySearch(int first
, int last
, int value
) {
63 //FIXME: should not return an integer
65 int middle
= (first
+ last
) / 2;
66 if (value
== int_array
[middle
])
68 else if (value
> int_array
[middle
])
69 return binarySearch((middle
+ 1), last
, value
);
70 return binarySearch(first
, (middle
- 1), value
);
73 public boolean supprimer(int value
) {
75 System
.out
.println("Aucune valeur à supprimer");
79 for (int i
= 0; i
< getCurrentSize(); i
++) {
80 if (int_array
[i
] == value
) {
81 // Deleting the element in the tab
82 for (int j
= i
; j
< getCurrentSize() - 1; j
++) {
83 int_array
[j
] = int_array
[j
+ 1];
92 private boolean isFull() {
93 return (getCurrentSize() >= getSize());
96 private boolean isEmpty() {
97 return (getCurrentSize() == 0);
100 public void afficher() {
101 String className
= this.getClass().getSimpleName();
102 System
.out
.println("---- " + className
+ " ----");
103 for (int i
= 0; i
< getCurrentSize(); i
++) {
104 System
.out
.println("element " + i
+ " : " + int_array
[i
]);