title: ArrayList and Queues
body: <p>My program, in short, is supposed to take a mainQueue LinkedList of integers, look at them all one-by-one, and sort them. Its examining the last digit of each integer, and placing them into corresponding subQueues. As of now, I am only to the ones place. and inserted to its subqueue. However, I cant figure out how to take all the numbers and sorted them and display them. Here is an example.  </p>
  
  <pre><code> mainQueue = { 12 50 215 100 85 539 16 35 } // Original Queue The numbers in the queues are placedin the subqueues depending on last digit on number if number is 50 its placed into subqueue 0. All of this works but I can get the numbers to then be sorted and display. Help please. Sorry for the formation of the code
  
  
  
  
   subQueue[0] = { 50 100 }
   subQueue[1] = { }
   subQueue[2] = { 12 }
   subQueue[3] = { }
   subQueue[4] = { }
   subQueue[5] = { 215 85 35 } 
   subQueue[6] = { 16 }
   subQueue[7] = { }
   subQueue[8] = { }
   subQueue[9] = { 539 }
   mainQueue = { 12 16 35 50 85 100 215 539 }
  
   import java.util.LinkedList; //LinkedList will be used as a queue
  
   public class Sorting 
     {
  private LinkedList&lt;Object&gt; mainQueue;
  private LinkedList[] subQueues;
  private final int SIZE = 10;
  private int maxDigits; //maximum number of digitszz
  
  //The constructor instantiates the mainQueue using the LinkedList,
  //subQueue array as an array of LinkedList using SIZE(10),
  //and initializes maxDigits = 0;
  public Sorting()
  {
  
      mainQueue = new LinkedList&lt;Object&gt;();
      subQueues = new LinkedList[SIZE];
      for ( int i = 0; i &lt; SIZE; ++i ) {
          subQueues[i] = new LinkedList();
      }
      maxDigits = 0;
  
  
  }
  
  
  public void addToMainQueue(Integer num)
  {
  
  
  
      mainQueue.add(num);
  
  }
  
  
  //The listMaintQueue method returns a string containing
  //the content of the main-queue
  public String listMainQueue()
  {
      return ("mainQueue = " + listQueue(mainQueue)+"\n");
  }
  
  
  //The listSubQueues method returns a string containing
  //the content of the sub-queues
  public String listSubQueues()
  {
      String result = "";
  
      for (int i=0; i&lt;SIZE; i++)
      {
          result += "subQueue[" + i + "]:";
          result += listQueue(subQueues[i]);
          result += "\n";
      }
      return result;
  }
  
  
  //The listQueue method returns a string containing
  //the content of the parameter queue
  public String listQueue(LinkedList&lt;Object&gt; queue)
  {
      LinkedList&lt;Object&gt; temp = new LinkedList&lt;Object&gt;();
      String result = "{ ";
  
      //Removing each element from the queue
      //and appending to the string to be returned
      while (!queue.isEmpty())
      {
          Object removed = queue.remove();
          result += removed + " ";
          temp.offer(removed);
      }
      result += "}\n";
  
      //Copying the temporary queue back to the
      //original queue
      while (!temp.isEmpty())
      {
          Object removed2 = temp.remove();
          queue.offer(removed2);
      }
      return result;
  }
  
  
  //The sortNumbers method sorts numbers in the main queue.
  public void sortNumbers() //This class performs the sortin
  {
  
  
      while (mainQueue.isEmpty() == false) //loop that checks if array is empty and places the lst digit into its corresponding subqueue.
      {
          Object lead = mainQueue.peek();
          mainQueue.remove();
          String digits = "" + lead;
          int digit = Integer.parseInt(digits.substring(digits.length()-1,       digits.length()));
  
  
  
          subQueues[digit].offer(lead);
  
      }
  
  
  
  
  
  
  
      System.out.print(listSubQueues());  //Step 5
  
  
  
  
      System.out.print(listMainQueue());  //Step 9
  
  
  
  
  
  }
  </code></pre>
  
  <p>}</p>