0

The following code creates a Sorting Array using Pointers and functions correctly. The issue I have is I want the array to sort, but put the zeros at the end. Any help would appreciated.

```
#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
void selectionSort( int * const, const int ); // prototype
void swap( int * const, int * const ); // prototype
int main()
{
const int arraySize = 8;
int a[ arraySize ] = { 3, 0, -5, 9, 22, 0, 14, 7 };
selectionSort( a, arraySize ); // sort the array
cout << "Integers in ascending order\n";
for ( int j = 0; j < arraySize; j++ )
cout << setw( 4 ) << a[ j ];
cout << endl;
return 0; // indicates successful termination
} // end main
// function to sort an array
void selectionSort( int * const array, const int size )
{
int smallest; // index of smallest element
for ( int i = 0; i < size - 1; i++ )
{
smallest = i; // first index of remaining array
// loop to find index of smallest element
for ( int index = i + 1; index < size; index++ )
if ( array[ index ] < array[ smallest ] )
smallest = index;
swap( &array[ i ], &array[ smallest ] );
}
}
// swap values at memory locations to which
// x and y point
void swap( int * const x, int * const y )
{
int temp = *x;
*x = *y;
*y = temp;
}
```

*Edited 3 Years Ago by Dani*: Formatting fixed