Algorithms and OOD (CSC 207 2014F) : EBoards

CSC207.01 2014F, Class 26: An Introduction to Sorting


Overview

Preliminaries

Admin

Upcoming Work

Notes from the Prologues

Good Things to Do

Extra Credit

Academic

Peer Support

Project Planning

Question: In the second half of the semester, you will do a project. There are three possibilities right now.

We'll do a quick discussion and then come back to the question immediately after break.

Questions

The problem of sorting

An object-oriented approach

Testing our sorting algorithm

    public void assertSorted(T[] whatever, Comparator<T> order)
    {
       for (int j = 1; j < whatever.length; j++)
         {
           if (order.compare(T[j-1],T[j]) > 0)
             fail("Order failed at position " + j);
         } // for
    } // assertSorted

    public Comparator<Integer> normalIntComparator = 
      (x,y) -> (x.compareTo(y));
    public Comparator<Integer> closerToZero =
      (x,y) -> { if (Math.abs(x) < Math.abs(y))
                   return -1;
                 else if (Math.abs(x) == Math.abs(y))
                   return 0;
                 else
                   return 1;
               }

    @Test
    public void testEmpty()
    {
      Integer[] empty = new Integer[0];
      arraySort(empty, normalIntegerComparor);
      assertSorted(empty, normalIntegerComparor);
    } // testEmpty

    @Test
    public void testFoo()
    {
      Integer[] foo = new Integer[] { 11, 1, 2, 5, 0, -4, 6 } ;
      arraySort(foo, normalIntegerComparator);
      assertSorted(foo, normalIntegerComparator);
    } // testFoo

    @Test
    public void testOne()
    {
    }

    @Test
    public void testTwo()
    {
    }

    @Test
    public void testThree()
    {
    }