Lecture 4 FIN,ITM
.pdf•102 // print one row of output showing the current
•103 // part of the array being processed
•104 void printRow( const int b[], int low, int mid,
•105 int high, int size )
•106 {
•107 // loop through entire array
•108 for ( int m = 0; m < size; m++ )
•109
•110 // display spaces if outside current subarray range
•111 if ( m < low || m > high )
•112 cout << " ";
•113
•114 // display middle element marked with a *
• |
115 |
else |
|
• |
116 |
if ( m == mid ) |
// mark middle value |
• |
117 |
||
• |
118 |
cout << setw( 3 ) << b[ m ] << '*'; |
|
•119
•120 // display other elements in subarray
• |
121 |
else |
• |
122 |
cout << setw( 3 ) << b[ m ] << ' '; |
•123
•124 cout << endl; // start new line of output
•125
•126 } // end function printRow
31
•
•Enter a number between 0 and 28: 6
•Subscripts:
• |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 10 11 12 13 14 |
|
|||||
• |
------------------------------------------------------------ |
24 |
26 |
28 |
||||||||||||
• |
0 |
2 |
4 |
6 |
8 |
10 |
12 |
14* 16 |
18 |
20 |
22 |
|||||
• |
0 |
2 |
4 |
6* |
8 |
10 |
12 |
|
|
|
|
|
|
|
|
|
•
• 6 found in array element 3
•
•
•
•Enter a number between 0 and 28: 25
•Subscripts:
• |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 10 11 12 13 14 |
|
|||||
• |
------------------------------------------------------------ |
24 |
26 |
28 |
||||||||||||
• |
0 |
2 |
4 |
6 |
8 |
10 |
12 |
14* 16 |
18 |
20 |
22 |
|||||
• |
|
|
|
|
|
|
16 |
18 |
20 |
22* 24 |
26 |
28 |
|
|
||
• |
|
|
|
|
|
|
|
|
|
|
24 26* 28 |
|
|
|
||
• |
|
|
|
|
|
|
|
|
|
|
24* |
|
|
|
|
|
•
•25 not found
32
•Enter a number between 0 and 28: 8
•Subscripts:
• |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 10 11 12 13 14 |
|||||
• |
------------------------------------------------------------ |
24 |
26 |
||||||||||||
• |
0 |
2 |
4 |
6 |
8 |
10 |
12 |
14* 16 |
18 |
20 |
22 |
||||
|
28 |
2 |
4 |
6* |
8 |
10 |
12 |
|
|
|
|
|
|
|
|
• |
0 |
|
|
|
|
|
|
|
|
||||||
• |
|
|
|
8 |
10* 12 |
|
|
|
|
|
|
|
|
||
• |
|
|
|
8* |
|
|
|
|
|
|
|
|
|
|
|
•
•8 found in array element 4
33
Readings:
•C++ How to Program, By H. M. Deitel
– Chapter 7. Arrays and Vectors
Thanks for your attention!
35
