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:
- Chapters 1 and 2:
-
Textual structure of a program (what you need to write).
- Integer variables.
- Arithmetic expressions.
- Sections 3.1, 3.2: Controlling program flow.
- "if" statements.
- Procedures.
- Sections 3.3, 3.4:
- Scope and Lifetimes of variables.
- Sections 4.1, 4.2:
- Conditionals in if statements.
- Sections 5.1, 5.2, 5.3: Looping constructs.
- "while" statements.
- "do while" statements.
- Sections 6.1, 6.2, 6.5:
- Arrays.
- Selection sort.
- Insertion sort.
Program: Finish the two sorting programs which we began in class:
- Selection Sort.
- Write procedure:
void swap(int a[], int i, int j)
which swaps the
values in locations i and j in array a.
- 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.
- Write procedure:
void selectionSort( int a[], int size )
which uses the two previous procedures to accomplish Selection Sort.
- Insertion Sort.
- Write procedure:
int findInsert( int a[], int i )
which returns the insertion place for the integer in array currently
at location i.
- 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.
- Write procedure:
void insertionSort( int a[], int size )
which uses the two previous procedures to accomplish Insertion Sort.