Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package td3;
- import td3interfaces.*;
- public class FileChainee implements File {
- public int nbElems = 0;
- public Cellule first;
- public FileChainee() {
- first = new Cellule(null, null);
- }
- @Override
- public void ajoutQueue(Object obj) {
- Cellule c = new Cellule(obj, first);
- first = c;
- nbElems++;
- }
- @Override
- public Object suppressionTete() {
- Cellule nextCellToCheck = first;
- for (int i = 0; i < nbElems - 1; i++) {
- nextCellToCheck = nextCellToCheck.getNextCell();
- }
- Object oldObj = nextCellToCheck.getObj();
- nextCellToCheck.setNextCell(null);
- nbElems--;
- return oldObj;
- }
- @Override
- public boolean estVide() {
- if (nbElems == 0)
- return true;
- else
- return false;
- }
- @Override
- public int taille() {
- return nbElems;
- }
- @Override
- public String toString() {
- Cellule nextCellToString = first;
- String str = "FileChainee de " + this.nbElems + " éléments : " + "\n";
- for (int i = 0; i < nbElems; i++) {
- nextCellToString = nextCellToString.getNextCell();
- if (i == 0)
- str += "Cellule de départ de la file : ";
- else
- str += "Cellule " + i + " : ";
- str += nextCellToString.toString() + ", " + "\n";
- }
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement