title: How to print the result of a heap insert (java)
body: <p>I'm currently working on a project in Java for a course in which I have to sort a list of cars in a heap then print out the result. However, due to the restrictions of the project, my insert method is void and I cannot print it directly. Arrays.toString will also not work as the heap is type E. Any ideas on how to print the result of the insert?  Here is the relevant code:</p>
  <pre><code>{
      public static void main(String[] args) throws IOException, HeapException
      {   
         Heap&lt;Car&gt; carHeap = new Heap&lt;&gt;();
         Car cars = new Car(year, make, model, type);
         carHeap.insert(cars);
      }
  }
  
  public void insert(E obj)
     {   
        tree.add(obj);
        int index = tree.size() - 1;
        while (index &gt; 0 &amp;&amp; cmp.compare(tree.get(index), tree.get((index - 1) / 2)) &gt; 0)
        {
          swap(index,((index - 1) / 2));
          index = (index - 1) / 2;
        }    
  
  private void swap(int place, int parent)
  {
    E temp = tree.get(place);
    tree.set(place,tree.get(parent));
    tree.set(parent,temp); 
  }
  </code></pre>