dsa

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

QueueInterface.java (1457B)


      1 package lab6;
      2 
      3 public interface QueueInterface<T> {
      4 
      5     public boolean isEmpty();
      6     // Determines whether a queue is empty.
      7     // Precondition: None.
      8     // Postcondition: Returns true if the queue is empty;
      9     // otherwise returns false.
     10 
     11     public void enqueue(T newItem) throws QueueException;
     12     // Adds an item at the back of a queue.
     13     // Precondition: newItem is the item to be inserted.
     14     // Postcondition: If the operation was successful, newItem
     15     // is at the back of the queue. Some implementations
     16     // may throw QueueException if newItem cannot be added
     17     // to the queue.
     18 
     19     public T dequeue() throws QueueException;
     20     // Retrieves and removes the front of a queue.
     21     // Precondition: None.
     22     // Postcondition: If the queue is not empty, the item that
     23     // was added to the queue earliest is removed. If the queue is
     24     // empty, the operation is impossible and QueueException is thrown.
     25 
     26     public void dequeueAll();
     27     // Removes all items of a queue.
     28     // Precondition: None.
     29     // Postcondition: The queue is empty.
     30 
     31     public T peek() throws QueueException;
     32     // Retrieves the item at the front of a queue.
     33     // Precondition: None.
     34     // Postcondition: If the queue is not empty, the item
     35     // that was added to the queue earliest is returned.
     36     // If the queue is empty, the operation is impossible
     37     // and QueueException is thrown.
     38 
     39     public String toString();
     40 }  // end QueueInterface
     41