#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int sz = 20;
void leerDatos(int v[]);
int aleatorio();
void intercambiar(int a[], int b[]);
bool buscar(int v[], int n, int dato);
void imprimir(int v[]);
int main()
{
int v1[sz];
int v2[sz];
srand(time(NULL));
cout << "\nIntroducir valores:\n";
leerDatos(v1);
intercambiar(v1, v2);
cout << "\nOrden aleatorio: ";
imprimir(v2);
cout << endl;
return 0;
}
void leerDatos(int v[])
{
for(int i = 0; i < sz; i++) {
cout << "(" << i + 1 << "/" << sz << "): ";
cin >> v[i];
}
}
int aleatorio() { return rand() % 20; }
void intercambiar(int a[], int b[])
{
int ids[sz];
int temp;
int i = 0;
while(i < sz) {
temp = aleatorio();
if(i == 0) {
ids[i] = temp;
b[temp] = a[i++];
} else if(buscar(ids, i, temp)) {
ids[i] = temp;
b[temp] = a[i++];
}
}
}
bool buscar(int v[], int n, int dato)
{
for(int i = 0; i < n; i++)
if(v[i] == dato) return false;
return true;
}
void imprimir(int v[])
{
for(int i = 0; i < sz; i++)
cout << v[i] << " ";
}