"how to send values to a selection sorting function" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to send values to a selection sorting function" answered properly. Developers are finding an appropriate answer about how to send values to a selection sorting function related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to send values to a selection sorting function. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to send values to a selection sorting function.
how to send values to a selection sorting function
1 // Fig. 8.15: fig08_15.cpp
2 // This program puts values into an array, sorts the values into
3 // ascending order and prints the resulting array.
4 #include <iostream>
5 using std::cout;
6 using std::endl;
7
8 #include <iomanip>
9 using std::setw;
10
11 void selectionSort( int * const, const int ); // prototype
12 void swap( int * const, int * const ); // prototype
13
14 int main()
15 {
16 const int arraySize = 10;
17 int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
18
19 cout << "Data items in original order\n";
20
21 for ( int i = 0; i < arraySize; i++ )
22 cout << setw( 4 ) << a[ i ];
23
24 selectionSort( a, arraySize ); // sort the array
25
26 cout << "\nData items in ascending order\n";
27
28 for ( int j = 0; j < arraySize; j++ )
29 cout << setw( 4 ) << a[ j ];
30
31 cout << endl;
32 return 0; // indicates successful termination
33 } // end main
34
35 // function to sort an array
36 void selectionSort( int * const array, const int size )
37 {
38 int smallest; // index of smallest element
39
40 // loop over size - 1 elements
41 for ( int i = 0; i < size - 1; i++ )
42 {
43 smallest = i; // first index of remaining array
44
45 // loop to find index of smallest element
46 for ( int index = i + 1; index < size; index++ )
47
48 if ( array[ index ] < array[ smallest ] )
49 smallest = index;
50
51 swap( &array[ i ], &array[ smallest ] );
52 } // end if
53 } // end function selectionSort
54
55 // swap values at memory locations to which
56 // element1Ptr and element2Ptr point
57 void swap( int * const element1Ptr, int * const element2Ptr )
58 {
59 int hold = *element1Ptr;
60 *element1Ptr = *element2Ptr;
61 *element2Ptr = hold;
62 } // end function swap
Source: www.gibmonks.com
All those coders who are working on the Whatever based application and are stuck on how to send values to a selection sorting function can get a collection of related answers to their query. Programmers need to enter their query on how to send values to a selection sorting function related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to send values to a selection sorting function for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to send values to a selection sorting function while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to send values to a selection sorting function". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to send values to a selection sorting function resolved professionally and stay updated to the latest Whatever updates.