# lecture_21 - ECE 190 Lecture 21 Problem solving with arrays...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 190 Lecture 21 Problem solving with arrays Lecture Topics Insertion sort Binary search Variable argument list and run-time stack Lecture materials Textbook Ch 16 Homework Machine problem MP4.1 due 4/6 MP4.2 due 4/14 Announcements / April 5, 2011 V. Kindratenko “§ Fragle'm gala/5w; ﬁyra'ﬁirg aha, degaﬁgtLI/Lg- ,_ .3 Ingerlﬁau _ 9 Pméf’em Svtw‘lwnmgl: pmlar 219144414113 0% (an wrigd 4;] sou/L; m1 am 4 5111;451:219“; acwu [515221441245 omluj *4) 6L > {mam/9k wﬁﬂﬂﬂ all wmwr 46¢! @19ng ' \n/ WEBB W ungor-FEJ 9w+eJ ﬂ umsor Jreoi gov-Mei “/ «mam» k at“ \$0Y‘4ecl ' W4ecf., [j “‘5 1749le £19va {wumﬂwg/‘ ‘ L 61‘ W’f‘ﬂl cm awry; vol Mum/Mg 516/ «Hm/Jim [we k4: ’ ‘ VNJ IuSMHom S9,“; [[941 [(S- / “Hz M); . 8M \$64” 4 [4‘31- E unsor {all ‘ *4: \$ 4 ‘Ewgw‘ffaf [.1ng Bar-18013 7 L ‘uuslpHeJ Ii—m My) [Sow-led H j = uusorwleJI ' L m P 5 Imus! Imp” Q»: [mi Mm, we”) * * L [144 uuWkJ, gmﬂJeJ; _ 1‘”; “”\$0V‘ie¢[ BM) ,, [41‘ [00? WWI/'vleo/ [#871445 7(‘/ _ _ 2cm (ungar¥e¢l=1/‘ cmsomLecl 4 n ;_uasrow4ee/ ++) _ _ unsorkiec/ Liam : [/94 Z‘uhspr—leo/J; /¥ M chvlec/ fix/n w/ HE JLWwﬂ, 90wa films owl/DZ we 9&sz ar/ N a 9’9174 «ﬂow uhSﬂve/«ec/f‘ém 1* 7(a)» {gow4fd: umgarJeJ—J ; ' (Sawk’cl >= 0) Q/ Q (U34 Eserec/J >uMSerec/l4wnJ} 949wa -_-) »{ E [IN [Sorka’ﬂ] = uuwﬂedféf’xm; H ﬂaw—l x/L L‘ﬂg‘L [99"‘11’14 9H 3 5 [/3 l L“ 9191" 3’ *‘kaJ (Lw‘ln‘autﬁ, {0&4 = auwk464 ") alt/soth 11m:- [z‘gi Mayoraler (drum/\$5 H » _ ¥ . . V1414 §0+M Ila/14\$ WWW", ,3 A72) )0: ‘72”. ~7._ .zg/cVI/w... .. .[email protected] ., @J. , ,, 81W 013 £091 5 am .4 (2521 g ... (SUM-)1] rﬂx’ad QZW~L 5, Kala/m F13; m ole/c Ma 0Lch aim/\$5 (a, w» ) .4 ,‘4 Ag doe; WVL ex/‘SQLI’M (91. '9 g/PMW WW ("9 (9, WW5 wah‘éf 1/1428 0r} meam/Jﬂi’ﬁig i 8M4 «msz 12\ 221 a; I ﬁbeﬁlno) IS} 381} \$8? (7?? 8’ ‘2 (JO/wa . ' ~ - W“ ”" wg WML lo (gel/1A N21ch 04 value 103 Shbi". >103, W3, FeyQLm/m WW Wong, dam/um?) (9150} la 9(5‘13: 9% Me 1412 and l J, 17. 772 \$1 ‘18 10%! £9,671: acilélog) QM, PBV‘CLOVW. WW 6Lng elemwmk (M33 L7 sum WA 30 004., ECE190 LechneZl Apﬁl5,2011' void InsertionSort(int array, int n) { int us, 3; int usItem; /* loop through us items */ for (us 2 1; us < n; us++) { usItem = array[us]; /* loop through items until we find a spot for usItem */ for (s = us—l; (5 >= 0) && (array[s] > usItem); s——) array[s+l] = array[s]; /* shift 3 items */ array[s+l] usItem; /* insert us item */ int BinarySearch(int item, int array, int n) { int start=0, end=n—l, middle; int found = -1; while (end >= start) { middle = (end + start) / 2; if (item == array[middle]) { found = middle; break; } else if (item < array[middle]) end = middle — 1; else start = middle + l; }; return found; 3 V. Kindratenko ECE190 Lecuﬂ821 Apﬁ|5,2011 #include <stdio.h> #include <stdlib.h> #define N 10 void getData(int array, int n); void printData(int array, int n); void InsertionSort(int array, int n); int main() { int list[N]; int item, found; /* generate random list */ getData(list, N); printData(list, N); /* call insertion sort */ InsertionSort(list, N); printData(list, N); /* get item from the user */ printf("Which number do you want to find in the list? "); scanf("%d", &item); /* call biary search */ found = BinarySearch<item, list, N); printf("ltem %d was %sfound in the list\n", item, (found==-l) ? "NOT " : ""); return 0; void getData(int array, int n) { int i; for (i = O; i < n; i++) array[i] = rand() / 1000000; } void printData(int array, int n) { int i; for (i = O; i < n; i++) printf("%d ", array[i]); printf("\n"); 2 V. Kindratenko [,ff’L/iyy\/&Yu'm/éé€ CQV V1 _ L L Z " 6144. Part/,1le wwal WW dam/LN) L‘MJr 9w; {Cm/194 (“/5wa ’{7Lor‘maé7l/ _ ' b7 PNle (we! SWP; We a Mair/“Mllemhum/é/wOV/ amguwmls lacegSABO/ ﬂz’s Mam/5% Q’Q‘ Pat/(OB 0V2 Mam/g” OWL icrzerlsz #19 W’ <MM~ ~—> +l/(£V‘«€ 1% c2 Que—720* pm MPMXﬁ-Mcleace élwaw 342% amt/me §Wég7zlbw I’M mpg! 7&2»va Sv/Mwéa Wc/ WM wwwwle Hues! 449%» #40, Mi. *5? RUM—13%? glam/J Lewd/2% Jug 37%;{7Ltrﬂh McZJLM‘IWZ/j‘ ‘> (KW 13: WWW/“NM mumsz 6%: r, K, E);- ‘7 (aw/MAJ 94ml 1‘9 vaWeJ f»: 12 3 MM WWW rag/I’m LWVLM 7L9»? Liam” me [mg Fe 5/ \> WMA ~F4m4\$ f9 QicewziMJ/ Jy'rgw/L MMszQ/z‘om 9W/V/L M4500) CLOYWQSJWMJQ vzo W “HI/“Qt; mew/wing [om wZ/DM dr’weMUg 69(th M9 [98419201 WW8 Fair 7L0 “Corm4_ #m’wg "9 Mikael .. _ \> WW1 1qu _ I’M 3W9 Care-Se] W; V“ W U WW“, W); ...
View Full Document

## This note was uploaded on 08/24/2011 for the course ECE 190 taught by Professor Hutchinson during the Spring '08 term at University of Illinois, Urbana Champaign.

### Page1 / 8

lecture_21 - ECE 190 Lecture 21 Problem solving with arrays...

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

View Full Document
Ask a homework question - tutors are online