title: How to create high priority bounded subqueue and low priority bounded subqueue in JAVA
body: <p>I have created a priority queue and filled the queue with items and using this queue as basis I iterated through it and found the priority of the items. Depending on the priority am moving items to subqueues using some logic.</p>
  
  <p>In my main program I created bounded subqueues using static statements what I would like to do is create the bounded subqueue using the constructor of my parent queue Constructor: <code>public HiLoPriorityQueue(int high_capacity, int low_capacity)</code>
  the constructor should create high priority bounded sub-queue with initial capacity high_capacity and a low priority bounded sub-queue with capacity low_capacity</p>
  
  <p>Can the subqueues be created from parent queue by using the same add and remove methods applied on the parent queue??</p>
  
  <p>My Main Program:</p>
  
  <pre><code>   public class PQTest {
  
      public static void main(String[] args) {
  
          HiLoPriorityQueue&lt;Customer&gt;  prq = new HiLoPriorityQueue&lt;Customer&gt;(10); 
          Customer c1 = new Customer("Rock",999);
          Customer c2 = new Customer("Brock",1);
          Customer c3 = new Customer("UnderTaker",1000);
  
          HiLoPriorityQueue&lt;Customer&gt;  hq = new HiLoPriorityQueue&lt;Customer&gt;(5);
          HiLoPriorityQueue&lt;Customer&gt;  lq = new HiLoPriorityQueue&lt;Customer&gt;(3);
  
  
          // insert values in the queue
          prq.add(c1);
          prq.add(c2);
          prq.add(c3);
  
  
          // create iterator from the queue
          Iterator it = prq.iterator();
  
          System.out.println ( "Priority queue values are: ");
          while (it.hasNext()){
              Customer c = (Customer) it.next();
              System.out.println ( "Value: "+ c);
              System.out.println("Priority is :: "+c.getPriority());
              if(c.getPriority() == 1){
                  if(hq.size() &lt; 5 )
                      hq.add(c);
                  else{
                      if(hq.size() &lt; 5 )  lq.add(c);
                      else{
                          lq.remove();
                          lq.add(c);
                      }
                  }
              }
              else{
                  if(lq.size() &lt; 3)   lq.add(c);
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>Queue creation class:</p>
  
  <pre><code>public class HiLoPriorityQueue&lt;E extends BinaryPrioritizable&gt; extends AbstractCollection{
  
  private int count;
  private Object[] elements;
  private Object[] helements;
  private Object[] lelements;
  private int head;
  private int tail;
  
  public HiLoPriorityQueue(int high_capacity, int low_capacity){
      helements = new Object[high_capacity];
      lelements = new Object[low_capacity];
      count = 0;
      head = 0;
      tail = 0;       
  }
  
  public HiLoPriorityQueue(int capacity)
  {
      elements = new Object[capacity];
      count = 0;
      head = 0;
      tail = 0;
  }
  
  
  
  @Override
  public Iterator&lt;E&gt; iterator()
       {
          return new Iterator&lt;E&gt;()
           {
           public boolean hasNext()
           {
           return visited &lt; count;
           }
  
           public E next()
           {
           int index = (head + visited) % elements.length;
           E r = (E) elements[index];
           visited++;
           return r;
           }
  
           public void remove()
           {
           throw new UnsupportedOperationException();
           }
  
           private int visited = 0;
       };
       }
  
   public boolean add(E anObject)
   {
       elements[tail] = anObject;
       tail = (tail + 1) % elements.length;
       count++;
       return true;
   }
  
   public E remove()
   {
       E r = (E) elements[head];
       head = (head + 1) % elements.length;
       count--;
       return r;
   } 
  
  @Override
   public int size()
   {
      return count;
   }
  
  
  
  }
  </code></pre>