Last active
February 25, 2016 16:51
-
-
Save MatonAnthony/4713844ed3277a1026b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListeDouble extends ListeSimple { | |
private Vecteur monVecteur; | |
public ListeDouble(){ | |
monVecteur = new VecteurTable(); | |
} | |
public int taille(){ | |
return monVecteur.taille(); | |
} | |
public boolean estVide(){ | |
return estVide(); | |
} | |
public Position premier(){ | |
return new Position(0); | |
} | |
public boolean estDernier(Position p){ | |
return (PositionImpl)p.getRang() == --taille(); | |
} | |
public Position suivant(Position p){ | |
return new Position(++(PositionImpl)p.getRang()); | |
} | |
public Object remplace(Position p, Object o){ | |
return remplace((PositionImpl)p.getRang(), o); | |
} | |
public Position insererEnTete(Object o){ | |
monVecteur.insere(taille(), o); | |
return taille(); | |
} | |
public Position insererApres(Position p, Object o){ | |
monVecteur.insere((PositionImpl)p.getRang(), o); | |
return ++(PositionImpl)p.getRang(); | |
} | |
public Object supprimer(Position p){ | |
return monVecteur.supprime((PositionImpl)p.getRang()); | |
} | |
public String toString(){ | |
return monVecteur.toString(); | |
} | |
public Position dernier(){ | |
return new Position(--taille()); | |
} | |
public boolean estPremier(Position p){ | |
// return monVecteur.element(0) == monVecteur.element((PositionImp)p.getRang()); | |
return 0 == (PositionImpl)p.getRang(); | |
} | |
public Position precedent(Position p){ | |
return new Position(--(PositionImpl)p.getRang()); | |
} | |
public Position insererEnFin(Object o){ | |
monVecteur.insere(taille(), o); | |
return new Position(--taille()); | |
} | |
public Position insererAvant(Position p, Object o){ | |
monVecteur.inserer(--((PositionImpl)p.getRang()), o); | |
return new Position(--((PositionImpl)p.getRang())); | |
} | |
public void permuter(Position p, Position q){ | |
Object swap = element((PositionImpl)q.getRang()); | |
monVecteur.remplace((PositionImpl)q.getRang(), element((PositionImpl) p.getRang())); | |
monVecteur.remplace((PositionImpl)p.getRang(), swap); | |
} | |
public class PositionImpl implements Position { | |
private int rang; | |
public PositionImpl(int rang){ | |
this.rang = rang; | |
} | |
public Object element(){ | |
return monVecteur.element(rang); | |
} | |
public int getRang(){ | |
return rang; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment