Need testing.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
private int binarySearch(int first, int last, int value) {
if (last < first)
- //FIXME: should not return an integer
+ //FIXME: should not return an integer
return -1;
int middle = (first + last) / 2;
if (value == int_array[middle])
}
public void afficher() {
- System.out.println("----");
+ String className = this.getClass().getSimpleName();
+ System.out.println("---- " + className + " ----");
for (int i = 0; i < getCurrentSize(); i++) {
System.out.println("element " + i + " " + int_array[i]);
}
}
public void afficher() {
- System.out.println("----");
+ String className = this.getClass().getSimpleName();
+ int i = 0;
+ System.out.println("---- " + className + " ----");
if (isEmpty()) {
- System.out.println("Liste vide");
+ return;
} else if (headNode.getNext() == null) {
- System.out.println("Valeur du noeud 0 : " + headNode.getData());
+ System.out.println("element " + i + " : " + headNode.getData());
} else {
- IntNode nodeCursor = headNode;
- int i = 0;
- while (nodeCursor.getNext() != null) {
- System.out.println("Valeur du noeud " + i + " : " + nodeCursor.getData());
- nodeCursor = nodeCursor.getNext();
+ IntNode nodeCursorNext = headNode.getNext();
+ System.out.println("element " + i + " : " + headNode.getData());
+ i++;
+ while (nodeCursorNext != null) {
+ System.out.println("element " + i + " : " + nodeCursorNext.getData());
+ nodeCursorNext = nodeCursorNext.getNext();
i++;
}
- System.out.println("Valeur du noeud " + i++ + " : " + nodeCursor.getData());
}
}
private int binarySearch(int first, int last, int value) {
if (last < first)
- //FIXME: should not return an integer
+ //FIXME: should not return an integer
return -1;
int middle = (first + last) / 2;
if (value == int_array[middle])
}
public void afficher() {
- System.out.println("---- entiers ----");
+ String className = this.getClass().getSimpleName();
+ System.out.println("---- " + className + " ----");
for (int i = 0; i < getCurrentSize(); i++) {
System.out.println("element " + i + " : " + int_array[i]);
}
}
public void afficher() {
- System.out.println("---- liste ----");
+ String className = this.getClass().getSimpleName();
+ int i = 0;
+ System.out.println("---- " + className + " ----");
if (isEmpty()) {
return;
} else if (headNode.getNext() == null) {
- System.out.println("element 0 : " + headNode.getData());
+ System.out.println("element " + i + " : " + headNode.getData());
} else {
- IntNode nodeCursor = headNode;
- int i = 0;
- while (nodeCursor.getNext() != null) {
- System.out.println("element " + i + " : " + nodeCursor.getData());
- nodeCursor = nodeCursor.getNext();
+ IntNode nodeCursorNext = headNode.getNext();
+ System.out.println("element " + i + " : " + headNode.getData());
+ i++;
+ while (nodeCursorNext != null) {
+ System.out.println("element " + i + " : " + nodeCursorNext.getData());
+ nodeCursorNext = nodeCursorNext.getNext();
i++;
}
- System.out.println("element " + i++ + " : " + nodeCursor.getData());
}
}
System.out.println("Aucune valeur à supprimer");
return false;
}
-
for (int i = 0; i < getCurrentSize(); i++) {
if (int_array[i] == value) {
// Deleting the element in the tab
}
public void compacter(int nElements) {
-
+ // Remove the last nElements
+ current_size -= nElements;
}
}
return rtVal;
}
+ public boolean supprimer(int index) {
+ boolean rtVal = false;
+ if (!isEmpty()) {
+ for (int j = index; (j < formeNumber - 1 && index < formeNumber); j++) {
+ formeCollection[j] = formeCollection[j + 1];
+ }
+ rtVal = true;
+ formeNumber--;
+ }
+ return rtVal;
+ }
+
public void afficher() {
for (int i = 0; i < formeNumber; i++) {
formeCollection[i].afficher();
}
public void compacter(int nElements) {
-
+ for (int i = formeNumber - 1; (i > formeNumber - nElements && !isEmpty()); i--) {
+ supprimer(i);
+ }
}
}
public void afficher() {
String className = this.getClass().getSimpleName();
+ int i = 0;
System.out.println("---- " + className + " ----");
if (isEmpty()) {
return;
} else if (headNode.getNext() == null) {
- System.out.println("element 0 : " + headNode.getData());
+ System.out.println("element " + i + " : " + headNode.getData());
} else {
- IntNode nodeCursor = headNode;
- int i = 0;
- while (nodeCursor.getNext() != null) {
- System.out.println("element " + i + " : " + nodeCursor.getData());
- nodeCursor = nodeCursor.getNext();
+ IntNode nodeCursorNext = headNode.getNext();
+ System.out.println("element " + i + " : " + headNode.getData());
+ i++;
+ while (nodeCursorNext != null) {
+ System.out.println("element " + i + " : " + nodeCursorNext.getData());
+ nodeCursorNext = nodeCursorNext.getNext();
i++;
}
- System.out.println("element " + i++ + " : " + nodeCursor.getData());
}
}
public void compacter(int nElements) {
-
+ // Remove the first nElements
+ if (isEmpty()) {
+ return;
+ } else if (nElements == 0) {
+ return;
+ } else if (headNode.getNext() == null) {
+ headNode = null;
+ } else {
+ // We have at least 2 nodes in the linked list
+ IntNode nodeCursor = headNode.getNext();
+ int i = 0;
+ // Go to the node at the nElements + 1 place
+ while (i < nElements - 1 && nodeCursor.getNext() != null) {
+ nodeCursor = nodeCursor.getNext();
+ i++;
+ }
+ // Set the nElements + 1 node as the root node
+ setHeadNode(nodeCursor);
+ }
}
}