3 author
= "Jérôme Benoit",
6 class Entiers
extends Structure
{
7 private int int_array
[];
8 private int array_size
;
9 private int current_size
;
11 public void setSize(int size
) {
15 public int getSize() {
19 public void setCurrentSize(int index
) {
23 public int getCurrentSize() {
28 int_array
= new int[size
];
33 public boolean inserer(int value
) {
35 System
.out
.println("Tableau plein");
43 for (int i
= 0; i
< getCurrentSize(); i
++) {
44 if (int_array
[i
] == value
) {
46 } else if (int_array
[i
] > value
) {
47 for (int j
= getCurrentSize(); j
> i
; j
--) {
48 int_array
[j
] = int_array
[j
- 1];
57 * The current value to add is > to all elements in the tab.
58 * So add it at the end.
60 int_array
[getCurrentSize()] = value
;
65 private int binarySearch(int first
, int last
, int value
) {
67 //FIXME: should not return an integer
69 int middle
= (first
+ last
) / 2;
70 if (value
== int_array
[middle
])
72 else if (value
> int_array
[middle
])
73 return binarySearch((middle
+ 1), last
, value
);
74 return binarySearch(first
, (middle
- 1), value
);
77 public boolean supprimer(int value
) {
79 System
.out
.println("Aucune valeur à supprimer");
82 for (int i
= 0; i
< getCurrentSize(); i
++) {
83 if (int_array
[i
] == value
) {
84 // Deleting the element in the tab
85 for (int j
= i
; j
< getCurrentSize() - 1; j
++) {
86 int_array
[j
] = int_array
[j
+ 1];
95 private boolean isFull() {
96 return (getCurrentSize() >= getSize());
99 private boolean isEmpty() {
100 return (getCurrentSize() == 0);
103 public void afficher() {
104 String className
= this.getClass().getSimpleName();
105 System
.out
.println("---- " + className
+ " ----");
106 for (int i
= 0; i
< getCurrentSize(); i
++) {
107 System
.out
.println("element " + i
+ " : " + int_array
[i
]);
111 public void compacter(int nElements
) {
112 if (current_size
- nElements
> 0) {
113 // Remove the last nElements
114 current_size
-= nElements
;