dsa

Data Structures & Algorithms - Spring 2018
Log | Files | Refs | README

Deq.java (760B)


      1 package lab6;
      2 
      3 public class Deq<T> extends Queue<T> implements ExtendedQueueInterface<T>{
      4 
      5     public void enqueueFirst(T newItem)
      6             throws ExtendedQueueException {
      7         if (numItems == items.length) {
      8             resize();
      9         }
     10         front = ((((front - 1) % items.length) + items.length) % items.length);
     11         items[front] = newItem;
     12         numItems++;
     13     }
     14 
     15     public T dequeueLast()
     16             throws ExtendedQueueException {
     17         back = ((((back - 1) % items.length) + items.length) % items.length);
     18         T item = items[back];
     19         items[back] = null;
     20         numItems--;
     21         return item;
     22     }
     23 
     24     public T peekLast() {
     25         return items[((((back - 1) % items.length) + items.length) % items.length)];
     26     }
     27 }