#
include
<iostream>
#
include
<time.h>
using
namespace
std;
void srandData(int *, int );
void bubbleSort(int *, int );
void swap(int *, int *);
void display(int *, int );
int main()
{
const
int N = 10;
int arr[N];
srandData(arr, N);
bubbleSort(arr, N);
display(arr, N);
return
0;
}
void srandData(int *a, int n)
{
srand(time(NULL));
for
(int i = 0; i < n; i++)
{
a[i] = rand() % 50;
cout << a[i] <<
" "
;
}
cout << endl;
}
void swap(int *b, int *c)
{
int temp = *c;
*c = *b;
*b = temp;
}
void bubbleSort(int *a, int n)
{
for
(int i = 0; i < n; i++)
{
for
(int j = 0; j < n - i - 1; j++)
{
if
(a[j] < a[j + 1])
{
swap(&a[j], &a[j + 1]);
}
}
}
}
void display(int *d, int n)
{
for
(int i = 0; i < n; i++)
{
cout << d[i] <<
" "
;
}
cout << endl;
}