repositories
/
TP_POO.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TP2: Simplify chained conditions.
[TP_POO.git]
/
TP2
/
Liste.java
diff --git
a/TP2/Liste.java
b/TP2/Liste.java
index 201d8750af17c7f0110e8bc852811ed446fea0c7..e042612b15c0f8abdf4bcc32e8bf48ea3829c14b 100644
(file)
--- a/
TP2/Liste.java
+++ b/
TP2/Liste.java
@@
-139,23
+139,22
@@
public class Liste extends Structure {
public void compacter(int nElements) {
// Remove the first nElements
public void compacter(int nElements) {
// Remove the first nElements
- if (isEmpty()) {
- return;
- } else if (nElements == 0) {
+ if (isEmpty() || nElements == 0) {
return;
return;
- } else if (headNode.getNext() == null) {
+ } else if (headNode
!= null && headNode
.getNext() == null) {
headNode = null;
} else {
// We have at least 2 nodes in the linked list
headNode = null;
} else {
// We have at least 2 nodes in the linked list
- IntNode nodeCursor = headNode
.getNext()
;
+ IntNode nodeCursor = headNode;
int i = 0;
int i = 0;
- // Go to the node at the nElements
+ 1
place
- while (i < nElements - 1 && nodeCursor.getNext() != null) {
+ // Go to the node at the nElements place
+ while (i < nElements - 1 && nodeCursor.getNext() != null
&& nElements > 1
) {
nodeCursor = nodeCursor.getNext();
i++;
}
// Set the nElements + 1 node as the root node
nodeCursor = nodeCursor.getNext();
i++;
}
// Set the nElements + 1 node as the root node
- setHeadNode(nodeCursor);
+ // It might be null
+ setHeadNode(nodeCursor.getNext());
}
}
}
}