50 likes | 179 Views
Instructor: Artem A. Lenskiy, PhD. Debugging practice. September 5, 2012. Bubble Sorting.
E N D
Instructor: Artem A. Lenskiy, PhD Debugging practice September 5, 2012
Bubble Sorting First Pass:( 65 3 1 8 7 2 4 ) ( 56 3 1 8 7 3 4), Compares and swaps them.( 5 63 1 8 7 2 4 ) ( 5 36 1 8 7 2 4 ), Swap since 6 > 3( 5 3 61 8 7 2 4 ) ( 5 3 16 8 7 2 4 ), Swap since 6 > 1( 5 3 6 18 7 2 4 ) ( 5 3 6 18 7 2 6 ), Does not swap them, (8 > 1), ( 5 3 6 1 8 7 2 4 ) ( 5 3 6 1 7 8 2 4 ), Swap since 8 > 7 ( 5 3 6 1 7 82 4 ) ( 5 3 6 1 7 28 4 ), Swap since 8 > 2 ( 5 3 6 1 72 8 4 ) ( 5 3 6 1 72 48 ), Swap since 8 > 2 Second Pass:( 5 3 6 1 72 4 8 ) ( 3 5 6 1 72 4 8 ), ( 3 5 6 1 72 4 8 ) ( 356 1 72 4 8 ), ( 35 6 1 72 4 8 ) ( 35 1 672 4 8 ), ( 35 6 1 7 2 4 8 ) ( 35 1 1 7 2 4 8 ), ( 35 6 1 7 24 8 ) ( 35 1 12 74 8 ), ( 35 6 12 74 8 ) ( 35 1 12 478 ), ( 35 1 124 78) ( 35 1 172 78), • Third Pass: ( 35 1 124 78 ) ( 35 1 172 78 ), N comparisons maximum N-1 comparisons Don’t need to call N-2 comparisons …
Bubble Sorting The program has to request list of number form command line Then the main function will have the following parameters To convert stings in argv[] to numbers user atoi(); The main function has to call sorting algorithm Bubble, that you have to implement: the Bubble function will have to call function Order, which swap values *p and *q, if *p>*q
Bubble Sorting (hinting code) Program output
Debugging in Visual C • Press F9 to set breakpoint • Press F5 to run your program • Press F10 execute your program step by step • Press F11 to step inside functions • To add variables to watch window either drag and drop variable you want to watch or select it and press right mouse click then press W.