hmwk2_sol_Cprogram_ch

hmwk2_sol_Cprogram_ch - /* * * * * * * */ homework2.c...

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

View Full Document Right Arrow Icon
/* * 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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
int j, k;
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

hmwk2_sol_Cprogram_ch - /* * * * * * * */ homework2.c...

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

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