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 the compacter method in the image class.
[TP_POO.git]
/
TP2
/
Image.java
diff --git
a/TP2/Image.java
b/TP2/Image.java
index 37bc6c3fc4d6b724c94db174b78f3e3bd79a8670..8289930d309e5e9f9bb18b5014386ac55b5b4f1d 100644
(file)
--- a/
TP2/Image.java
+++ b/
TP2/Image.java
@@
-67,9
+67,16
@@
class Image extends Forme implements Compactable {
}
public void compacter(int nElements) {
}
public void compacter(int nElements) {
- int minIndex = formeNumber - nElements - 1;
+ // Heavy solution
+ /* int minIndex = formeNumber - nElements - 1;
for (int i = formeNumber - 1; (i > minIndex && !isEmpty()); i--) {
supprimer(i);
for (int i = formeNumber - 1; (i > minIndex && !isEmpty()); i--) {
supprimer(i);
+ } */
+ // Lightweight solution
+ if (formeNumber - nElements > 0) {
+ formeNumber -= nElements;
+ } else {
+ formeNumber = 0;
}
}
}
}