1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
using namespace std;
int const N = 10; // This should be 10, not 20
void pirmaisMasivs(int masivs[], int N);
int main ()
{ int masivs[N] = {5,4,2,6,1,3,8,9,10,7}; // Declare in main
cout << "Numbers being sorted - 5,4,2,6,1,3,8,9,10,7 > " << endl;
pirmaisMasivs (masivs, N);
for (int i=0; i<N; i++)
cout << masivs[i] << endl;
system ("pause");
}
void pirmaisMasivs(int masivs[], int N)
{ int temp;
for( int i = 0; i < N - 1; i++ )
{ for( int j = 0; j < N - 1; j++ )
{ if( masivs[ j ] > masivs[ j + 1 ])
{ temp = masivs[ j ];
masivs[ j ] = masivs[ j + 1];
masivs[ j + 1 ] = temp;
}
}
}
}
|