Homework Assignment 6

Assigned: Wednesday, February 28.
Due: Wednesday, March 6.

Read: Read 6.1, 6.2 and 6.5.

Review what you should have read so far:

  1. Chapters 1 and 2:
  2. Sections 3.1, 3.2: Controlling program flow.
  3. Sections 3.3, 3.4:
  4. Sections 4.1, 4.2:
  5. Sections 5.1, 5.2, 5.3: Looping constructs.
  6. Sections 6.1, 6.2, 6.5:

Program: Finish the two sorting programs which we began in class:

  1. Selection Sort.
    1. Write procedure:
      void swap(int a[], int i, int j)
      which swaps the values in locations i and j in array a.
    2. Write procedure:
      int findLargest( int a[], int size, int i )
      which returns the index of the integer of largest value in the array a and with index between i and size-1.
    3. Write procedure:
      void selectionSort( int a[], int size )
      which uses the two previous procedures to accomplish Selection Sort.

  2. Insertion Sort.
    1. Write procedure:
      int findInsert( int a[], int i )
      which returns the insertion place for the integer in array currently at location i.
    2. Write procedure:
      void insert( int a[], int i, int j)
      which inserts value of a[i] into location j and shifts down by one index the values at locations j, j+1, ... i-1.
    3. Write procedure:
      void insertionSort( int a[], int size )
      which uses the two previous procedures to accomplish Insertion Sort.