Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static boolean drawColumn (int[][] colorArray, int[] current, int column)
- {
- if (column >= colorArray.length)
- {
- //array is full
- return true;
- }
- for (int n = 0; n < current.length; n++)
- {
- colorArray[column][n] = current[n];
- //System.out.println(initial[n]);
- }
- return false;
- }
- private static int[][] insertionSort(int length, int[] current)
- {
- //do image for insertion sort
- //length is the desired number of columns to draw
- //current is an array of ints which represent colors
- //initially, current is already sorted
- int presentColumn = 0; //track the traversal through the image array
- int rowCount = current.length; //number of items to sort/number of rows in the
- //image
- //shuffle the sorted array so we can do our own sorting
- current = randomShuffle(current);
- //array to be returned:
- //2d matrix of ints which represent colors (8-bit RGB by default)
- int[][] colorArray = new int[length][rowCount];
- boolean swapped;
- boolean fullArray = false; //track whether colorArray is full
- //draw unsorted column
- fullArray = drawColumn(colorArray, current, presentColumn);
- presentColumn++;
- //do insertion sort
- for (int n = 1; n < (current.length); n++)
- {
- int elem = current[n];
- int indexHole = n;
- while(indexHole > 0 && current[indexHole - 1] > elem)
- {
- fullArray = drawColumn(colorArray, current, presentColumn);
- presentColumn++;
- current[indexHole] = current[indexHole - 1];
- indexHole--;
- }
- fullArray = drawColumn(colorArray, current, presentColumn);
- presentColumn++;
- current[indexHole] = elem;
- }
- //the elements are now sorted, but keep drawing until the end of the array is reached
- while (!fullArray)
- {
- fullArray = drawColumn(colorArray, current, presentColumn);
- presentColumn++;
- }
- return colorArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement