Esempio n. 1
0
 protected void reBalance() {
   // the front and back can have a delta of 0 or 1.
   // If this is 2 you will pop an item front the front/back and add it to the back/front
   if (front.size() == back.size() + 2) {
     back.add(0, front.remove(front.size() - 1));
     // Or vise versa
   } else if (back.size() == front.size() + 2) {
     front.add(front.size(), back.remove(0));
   }
 }
Esempio n. 2
0
 public T remove(int i) {
   // Declare
   T x;
   // If i is in front then remove element i
   if (i < front.size()) x = front.remove(i);
   // else remove from back position i (less mod front)
   else x = back.remove(i - front.size());
   // Must rebalance as this may unbalance our array
   reBalance();
   return x;
 }