lecture_20_revised

lecture_20_revised - , i ); scanf(...

Info iconThis preview shows pages 1–8. 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
1 · insert.cc · 2010-10-28 08:31 · David Nicol #include <stdio.h> int GetArray( int [], int *); void InsertionSort( int [], int ); void PrintArray( const char *, int [], int ); int main() { int glist[10]; int glistlen=0; if (GetArray(glist, &glistlen) < 0 ) { return -1; } PrintArray( "------ unsorted list --------\n" , glist, glistlen); InsertionSort(glist,glistlen); PrintArray( "------ sorted list --------\n" , glist, glistlen); } int GetArray( int list[], int *n) { int i; printf( "enter list length between 1 and 10 elements: " ); scanf( "%d" , n); if ( *n<1 || *n > 10 ) return -1; for (i=0; i<*n; i++) { printf( "enter list[%d] : "
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: , i ); scanf( &quot;%d&quot; , list+i); } return 0; } void InsertionSort( int list, int n) { int unsorted, sorted; int unsortedItem; for (unsorted=1; unsorted&lt;n; unsorted++) { unsortedItem = list[unsorted]; for (sorted=unsorted-1; (sorted&gt;=0) &amp;&amp; (list[sorted]&gt;unsortedItem); sorted--) { list[sorted+1] = list[sorted]; } list[sorted+1] = unsortedItem; } } void PrintArray( const char *msg, int list, int n) { int i; printf( &quot;%s&quot; , msg); for (i=0; i&lt;n; i++) { printf( &quot;%d%c&quot; , list[i], ((i+1)%4? '\t' : '\n' )); } printf( &quot;\n&quot; ); }...
View Full Document

This note was uploaded on 08/29/2011 for the course ECE 265 taught by Professor Kosbar during the Fall '09 term at Missouri S&T.

Page1 / 8

lecture_20_revised - , i ); scanf(...

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

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