Skip to content
Snippets Groups Projects
Commit 3d1a0981 authored by RADELLAH Badr's avatar RADELLAH Badr
Browse files

Ex1 tp1

parent 22682e68
No related branches found
No related tags found
No related merge requests found
Pipeline #31087 passed
......@@ -52,9 +52,13 @@ public class Vector {
public void resize(int newSize) {
ensureCapacity(newSize);
if (newSize > size) {
Arrays.fill(elements, size, newSize, 0);
}
this.size = newSize;
}
/**
* Retourne la capacité du vecteur.
*
......@@ -64,9 +68,29 @@ public class Vector {
return elements.length;
}
public int size() { return 0; }
public boolean isEmpty() { return false; }
public void add(int element) { }
public void set(int index, int element) { }
public int get(int index) { return 0; }
public int size() {
return size;
}
public boolean isEmpty() {
return size == 0;
}
public void add(int element) {
ensureCapacity(size + 1);
elements[size] = element;
size++;
}
public void set(int index, int element) {
if (index >= 0 && index < size) {
elements[index] = element;
}
}
public int get(int index) {
if (index >= 0 && index < size) {
return elements[index];
}
return 0;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment