Monday, December 8, 2014

12/8/14

Today I continued my work on Searching and Sorting. For the most part so far, it focuses on the selectionSort method:

public static void selectionSort( Item[] array )
{
  int i, k, posmax;
  Item temp;
  for ( i = array.length - 1 ; i > 0 ; i-- )
  {
    posmax = 0;
    for ( k = 1 ; k <= i ; k++ )
    {
      if ( array[ k ].compareTo( array[ posmax ] ) > 0 )
      posmax = k;
    }
    temp = array[ i ];
    array[ i ] = array[ posmax ];
    array[ posmax ] = temp;
  }
}

I've been doing my best today to try to memorize this, however I'm still working on it. I reached the first activity of the chapter, which I can hopefully complete tomorrow.

1 comment:

  1. Don't try to memorize the implementation. Instead, make sure you intimately understand the abstraction. In other words, it would be more useful if you could sketch how a selection sort proceeds on a white board with numbers and arrows, then to try to memorize the Java implementation. Once you really understand the abstraction, the implementation will be easy to reconstruct.l

    ReplyDelete