hmwk2_sol_Cprogram_ch

# hmwk2_sol_Cprogram_ch - homework2.c Description Sorting...

This preview shows pages 1–2. Sign up to view the full content.

/* * homework2.c * Description: Sorting Methods * Created on: Dec 4, 2010 * Author: * Class: COMPE271 * Professor: */ #include <stdio.h> #include <stdlib.h> #include <tchar.h> //----------------------------------------------------------------------- // Insertion Sort void insertion_sort ( int numbers[], int max) { int i, j, k; int value; k = 0; for (i = 1 ; i < max; i++) { value = numbers[i]; j = i-1; while (j >= 0 && numbers[j] > value ) { numbers[j + 1] = numbers[j]; j = j-1; } numbers[j+1] = value; } } //----------------------------------------------------------------------- // Exchange sort void exchange_sort ( int numbers[], int max) { int i, j, k; int value; k = 0; for (i = 0 ; i < max-1; i++) { for (j = i+1; j < max; j ++) { if (numbers[i] <= numbers[j]) { value = numbers[i]; numbers[i] = numbers[j]; numbers[j] = value; } } } } //----------------------------------------------------------------------- // Bubble sort void bubble_sort ( int numbers[], int max) { //int i, j, k;

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

View Full Document
int j, k;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

hmwk2_sol_Cprogram_ch - homework2.c Description Sorting...

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

View Full Document
Ask a homework question - tutors are online