Package algs24

Class XFixedMinPQ<K extends Comparable<? super K>>

java.lang.Object
algs24.XFixedMinPQ<K>
All Implemented Interfaces:
Iterable<K>

public class XFixedMinPQ<K extends Comparable<? super K>> extends Object implements Iterable<K>
  • Nested Class Summary Link icon

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
     
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    private final int
     
    private int
     
    private final K[]
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    XFixedMinPQ(int initCapacity)
    Create an empty priority queue with the given initial capacity, using the given comparator.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    Delete and return the smallest key on the priority queue.
    private void
    exch(int i, int j)
     
    private boolean
    greater(int i, int j)
     
    void
    insert(K x)
    Add a new key to the priority queue.
    boolean
    Is the priority queue empty?
    boolean
    Is the priority queue full?
    private boolean
     
    private boolean
    isMinHeap(int k)
     
    Return an iterator that iterates over all of the keys on the priority queue in ascending order.
    static void
    main(String[] args)
    A test client.
    min()
    Return the smallest key on the priority queue.
    private void
     
    private void
    sink(int k)
     
    int
    Return the number of items on the priority queue.
    private void
    swim(int k)
     

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable Link icon

    forEach, spliterator
  • Field Details Link icon

    • pq Link icon

      private final K extends Comparable<? super K>[] pq
    • N Link icon

      private int N
    • MAXN Link icon

      private final int MAXN
  • Constructor Details Link icon

    • XFixedMinPQ Link icon

      public XFixedMinPQ(int initCapacity)
      Create an empty priority queue with the given initial capacity, using the given comparator.
  • Method Details Link icon

    • isEmpty Link icon

      public boolean isEmpty()
      Is the priority queue empty?
    • isFull Link icon

      public boolean isFull()
      Is the priority queue full?
    • size Link icon

      public int size()
      Return the number of items on the priority queue.
    • min Link icon

      public K min()
      Return the smallest key on the priority queue. Throw an exception if the priority queue is empty.
    • insert Link icon

      public void insert(K x)
      Add a new key to the priority queue.
    • delMin Link icon

      public K delMin()
      Delete and return the smallest key on the priority queue. Throw an exception if the priority queue is empty.
    • swim Link icon

      private void swim(int k)
    • sink Link icon

      private void sink(int k)
    • greater Link icon

      private boolean greater(int i, int j)
    • exch Link icon

      private void exch(int i, int j)
    • isMinHeap Link icon

      private boolean isMinHeap()
    • isMinHeap Link icon

      private boolean isMinHeap(int k)
    • iterator Link icon

      public Iterator<K> iterator()
      Return an iterator that iterates over all of the keys on the priority queue in ascending order.

      The iterator doesn't implement remove() since it's optional.

      Specified by:
      iterator in interface Iterable<K extends Comparable<? super K>>
    • showHeap Link icon

      private void showHeap()
    • main Link icon

      public static void main(String[] args)
      A test client.