#include<iomanip>
#include<iostream>
#include<cmath>
#include<windows.h>
#include<process.h>
#include<cstdlib>
using namespace std;
double Generuj(float a, float b)
{ double w = (a + (b - a)*(double)rand()/RAND_MAX);
return floor(w * 100 + 0.5)/100; }
void Swap(double *a, double *b)
{ double temp = *a; *a = *b; *b = temp; }
void WatekGlowny(int, char);
void DispV(int, double *, char *);
VOID GenVec(LPVOID);
VOID BubbleSort(LPVOID);
struct PARM {
int nData;
double a, b;
double *X;
char zn;
};
int main() // Watek3
{
DWORD T1, time;
int nData = 50000;
double *A = new double[nData];
double *B = new double[nData];
PARM parmGA = {nData, 1.1, 9.9, A, 'A'},
parmGB = {nData, 10.1, 19.9, B, 'B'};
PARM parmSA = {nData, 0, 0, A, 'C'},
parmSB = {nData, 0, 0, B, 'D'};
T1 = GetTickCount();
_beginthread(GenVec, 0, &parmGA);
_beginthread(GenVec, 0, &parmGB);
_beginthread(BubbleSort, 0, &parmSA);
_beginthread(BubbleSort, 0, &parmSB);
WatekGlowny(300, '*');
time = GetTickCount() - T1;
cout << "czas = " << time << endl;
DispV(100, A, "vektor A po sortowaniu:");
cout << "Koniec - Wcisnij Enter"; cin.get();
delete [] A, B;
return 0;
}
VOID GenVec(LPVOID parametr)
{
PARM *parm = (PARM*)parametr;
int n = parm->nData;
double oda = parm->a, dob = parm->b, *X = parm->X;
for (int i = 0; i < n; i++){
X[i] = Generuj(oda, dob);
if (i%100 == 0) cout <<parm->zn;
}
}
VOID BubbleSort(LPVOID parametr)
{
// Sleep(100);
PARM *parm = (PARM*)parametr;
int size = parm->nData;
double *X = parm->X;
for (int i = 1; i < size; i++){
if (i%100 == 0) cout <<parm->zn;
for (int j = size-1; j >= i; j--)
if (X[j] < X[j - 1]) Swap(&X[j-1], &X[j]);
}
}
void DispV(int ile, double V[], char *text )
{
cout << text;
for(int i=0; i < ile; i++) {
if (i%8 == 0) cout << endl;
cout << setw(9) << V[i];
}
cout << endl;
}
void WatekGlowny(int n, char zn) // długotrwałe obliczenia
{
double w;
for (int k1=0; k1 < n; k1++){
for (int k2=0; k2<20000; k2++) w = pow(sin(k1),3.3)* pow(cos(k1),2.2);
cout << zn <<" ";
} cout << "\n";
}