Advertisement
bebesurf

FileChainee.java

May 25th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package td3;
  2.  
  3. import td3interfaces.*;
  4.  
  5. public class FileChainee implements File {
  6.  
  7.     public int nbElems = 0;
  8.     public Cellule first;
  9.  
  10.     public FileChainee() {
  11.         first = new Cellule(null, null);
  12.     }
  13.  
  14.     @Override
  15.     public void ajoutQueue(Object obj) {
  16.         Cellule c = new Cellule(obj, first);
  17.         first = c;
  18.         nbElems++;
  19.     }
  20.  
  21.     @Override
  22.     public Object suppressionTete() {
  23.         Cellule nextCellToCheck = first;
  24.         for (int i = 0; i < nbElems - 1; i++) {
  25.             nextCellToCheck = nextCellToCheck.getNextCell();
  26.         }
  27.         Object oldObj = nextCellToCheck.getObj();
  28.         nextCellToCheck.setNextCell(null);
  29.         nbElems--;
  30.         return oldObj;
  31.     }
  32.  
  33.     @Override
  34.     public boolean estVide() {
  35.         if (nbElems == 0)
  36.             return true;
  37.         else
  38.             return false;
  39.     }
  40.  
  41.     @Override
  42.     public int taille() {
  43.         return nbElems;
  44.     }
  45.  
  46.     @Override
  47.     public String toString() {
  48.         Cellule nextCellToString = first;
  49.         String str = "FileChainee de " + this.nbElems + " éléments : " + "\n";
  50.         for (int i = 0; i < nbElems; i++) {
  51.             nextCellToString = nextCellToString.getNextCell();
  52.             if (i == 0)
  53.                 str += "Cellule de départ de la file : ";
  54.             else
  55.                 str += "Cellule " + i + " : ";
  56.            
  57.             str += nextCellToString.toString() + ", " + "\n";
  58.         }
  59.         return str;
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement