13_ArraysC(Oct.27)

13_ArraysC(Oct.27) - APSC 160 Arrays C Oct. 27-2010 Q3...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
APSC 160 Arrays C Oct. 27-2010 Q3 & 4 (selectionSort.c) /* * Author: Paul Carter * Date: March 5, 2010 * Purpose: A driver program to test the implementation * of our selection sort algorithm. */ #include <stdio.h> #include <stdlib.h> #define SIZE 8 int indexOfSmallest( int data[], int size, int startIndex ); void sort( int data[], int size ); void printArray( int data[], int size ); int main( void ) { int data1[] = { -123, 15, -4, 9, -8, 12, 6, -68 }; int data2[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; int data3[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; /* sort an array of size 1 */ sort( data1, 1 ); printArray( data1, 1 ); printf( "\n\n" ); /* sort a typical array */ sort( data1, SIZE ); printArray( data1, SIZE ); printf( "\n\n" ); /* the next two tests are checking for off-by-one errors and ensure that our search for the smallest item starts and ends in the right place */ /* sort an array that's already sorted - in this case the smallest item is always found at startIndex - this checks that our search starts at the right place */ sort( data2, SIZE ); printArray( data2, SIZE ); printf( "\n\n" ); /* sort an array that's sorted in the wrong order - in this case the smallest item is always found at the end of the array - this checks that our search
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

13_ArraysC(Oct.27) - APSC 160 Arrays C Oct. 27-2010 Q3...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online