@Override
	public Step[][] solve(int[] initialValues) {
            // byte array to hold values in each step of the solution.
		byte[] values = new byte[initialValues.length];
                int[] ranks = new int[initialValues.length];
		/*
		 * Add values array passed into gui into the "values" array as bytes
		 */
		for (int i = 0; i < initialValues.length; i++) {
			values[i] = (byte) initialValues[i];
		}
                for (int j = 0; j < initialValues.length; j++) {
                    ranks[j] = 0;
                }
		/*
		 * Variables: allSteps = an ArrayList that hold only ArrayLists that
		 * hold only steps. n = the length of the array doMore = boolean that
		 * decides when to stop.
		 */
		ArrayList<ArrayList<Step>> allSteps = new ArrayList<ArrayList<Step>>();
		int n = initialValues.length;

		/*
		 * http://www.leepoint.net/notes-java/data/arrays/31arrayselectionsort.html
		 * Follow the weblink to find examples of Se;ection Sort. This algorithm
		 * is the first type, which is a simple Selection Sort.
		 */
                
		for (int pass = 1; pass < values.length; pass++) {
			/*
			 * First we create a new ArrayList that holds only structures of
			 * type step. This list will hold all of the steps in one pass of
			 * the algorithm
			 */
			ArrayList<Step> currentSteps = new ArrayList<Step>();
			for (int j = 0; j < pass; j++) {

				/*
				 * Compare Step: The indices of the two values currently being
				 * compared are passed into the SelectionCompareStep class. Here
				 * the color will be changed on these indices to show that they
				 * are currently being compared. The value array is also passed
				 * in to be stored to the theValues array in the step structure.
				 * Once the colors have been changed and the values array has
				 * been stored, the Step structure is created and stored into
				 * the ArrayList currentSteps which only holds Steps.
				 */
                                 currentSteps.add(new RankCompareStep(values.clone(), 
                                         ranks.clone(), pass, j));

				/*
				 * RANK Step: If a swap is needed, the SelectionSwapStep class
				 * will be created with the current values array and the indices
				 * of the two values that need to be swapped. The color will be
				 * changed on these two values in the color array and the value
				 * array will be stored in the step structure. This step
				 * structure will then be added to the ArrayList currentSteps,
				 * which holds the steps in one pass of the algorithm. The
				 * values are then swapped.
				 */
                                if (values[j] <= values[pass]) {
                                    ranks[pass]++;
                                    currentSteps.add(new RankUpStep(values.clone(), ranks.clone(),
							pass));
                                }
                                else { 
                                    ranks[j]++;
                                    currentSteps.add(new RankUpStep(values.clone(), ranks.clone(),
							j));
                                }       
                        }
                        
                        allSteps.add(currentSteps);
                }
                        
                /*
                 * Swap Step: If a swap is needed, the SelectionSwapStep class
                 * will be created with the current values array and the indices
                 * of the two values that need to be swapped. The color will be
                 * changed on these two values in the color array and the value
                 * array will be stored in the step structure. This step
                 * structure will then be added to the ArrayList currentSteps,
                 * which holds the steps in one pass of the algorithm. The
                 * values are then swapped.
                 */
               
                    byte [] temp=values.clone();
                    for (int z=0;z<values.length;z++) {
                        values[z]=-1;
                    }
                    int [] sortedranks = new int [ranks.length];
                    for (int z=0;z<values.length;z++) {
                        sortedranks[z] = -1;
                    }
               
                for(int i = 0; i < values.length; i++) {
                    ArrayList<Step> currentSteps = new ArrayList<Step>();
                    values[ranks[i]] = temp[i];
                    sortedranks[ranks[i]]=ranks[i];
                    
                    currentSteps.add(new RankHighlightStep(values.clone(), temp.clone(),
                            ranks.clone(), sortedranks.clone(),
                            ranks[i], i));
                    
                    currentSteps.add(new RankRemoveStep(values.clone(), temp.clone(),
                            ranks.clone(), sortedranks.clone(),
                            ranks[i], i));
                    temp[i] = -1;
                    
                    allSteps.add(currentSteps);
                }
                
                        
                           /*
			 * Once we have made one pass through the algorithm, the ArrayList
			 * currentSteps is stored into the ArrayList allSteps. allSteps
			 * holds all of the steps in the solution. At each index it holds
			 * all of the steps in one pass of the algorithm.
			 */
			
                    
                return Convert.toArray(allSteps);
	}