Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /* AISD-Lab.2 */
- /******************************************************************************/
- /* Grzegorz Janczyk */
- /* Instytut Mikroelektroniki i Optoelektroniki */
- /* Politechnika Warszawska */
- /* ul. Koszykowa 75 */
- /* 00-662 WARSZAWA */
- /* tel. (+48)(22) 660 72 07 */
- /* www.imio.pw.edu.pl */
- /******************************************************************************/
- #define _MAIN_CPP_
- #include "main.h"
- #include "dane.h"
- #include "sortowanie.h"
- /******************************************************************************/
- /************** inicjalizacja/sprzatanie/generacja INT ************************/
- /******************************************************************************/
- void InitINT(){ //inicjalizacja programowych struktur danych
- srand(Srand);
- SortINT = new AlgorytmySortowaniaINT(Licznosc);
- if(!SortINT)throw ERR_Object;
- //WypelnijINT_1();
- WypelnijINT_1();
- /*
- SortINT->GetDaneKopia()[0] =9;
- SortINT->GetDaneKopia()[1] =7;
- SortINT->GetDaneKopia()[2] =5;
- SortINT->GetDaneKopia()[3] =8;
- SortINT->GetDaneKopia()[4] =8;
- SortINT->GetDaneKopia()[5] =8;
- SortINT->GetDaneKopia()[6] =7;
- SortINT->GetDaneKopia()[7] =3;
- SortINT->GetDaneKopia()[8] =11;
- SortINT->GetDaneKopia()[9] =1;
- memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
- */
- SortINT->WypiszStanNaEkran(Ekran);
- if(Ekran){
- printf("Zbior poczatkowy\n");
- printf("\n************************\n");
- }
- SortINT->ZapiszStanDoPliku((char*)"Start");
- };
- void WypelnijINT_1(){ //pesymistyczny
- int a = Licznosc-1;
- int i;
- for(i=0;i<SortINT->GetLicznosc();i++){
- SortINT->GetDaneKopia()[a] = i;
- a = a - 1;
- memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
- }
- }
- void WypelnijINT_2(){
- double x1, x2, w, y1, y2;
- for(int i=0;i<SortINT->GetLicznosc();i++){
- do{
- x1=2.0*rand()/RAND_MAX-1.0;
- x2=2.0*rand()/RAND_MAX-1.0;
- w=x1*x1+x2*x2;
- }while(w>=1.0);
- w=sqrt((-2.0*log(w))/w);
- y1=x1*w;
- y2=x2*w;
- SortINT->GetDaneKopia()[i]=abs((int)(y2-y1));
- }
- memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
- }
- void WypelnijINT_3(){
- for(int i=0;i<SortINT->GetLicznosc();i++){
- /******************************************************************************/
- //int tablica[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- SortINT->GetDaneKopia()[i] = i;
- /******************************************************************************/
- }
- memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
- }
- /******************************************************************************/
- /************** inicjalizacja/sprzatanie/generacja BI *************************/
- /******************************************************************************/
- void InitBI(){ //inicjalizacja programowych struktur danych
- srand(Srand);
- SortBI = new AlgorytmySortowaniaBI(Licznosc);
- if(!SortBI) throw ERR_Object;
- WypelnijBI_1();
- SortBI->WypiszStanNaEkran(Ekran);
- if(Ekran){
- printf("Zbior poczatkowy\n");
- printf("\n************************\n");
- }
- SortBI->ZapiszStanDoPliku((char*)"Start");
- };
- void WypelnijBI_1(){ // rozklad normalny
- int i;
- //char (*stringi)[16]=new char[16][16];
- char stringi[16][16];
- strcpy(stringi[0],"A");
- strcpy(stringi[1],"B");
- strcpy(stringi[2],"C");
- strcpy(stringi[3],"D");
- strcpy(stringi[4],"E");
- strcpy(stringi[5],"F");
- strcpy(stringi[6],"G");
- strcpy(stringi[7],"H");
- strcpy(stringi[8],"J");
- strcpy(stringi[9],"K");
- strcpy(stringi[10],"L");
- strcpy(stringi[11],"M");
- strcpy(stringi[12],"N");
- strcpy(stringi[13],"P");
- strcpy(stringi[14],"R");
- strcpy(stringi[15],"S");
- for(i=0;i<SortBI->GetLicznosc();i++){
- SortBI->GetDaneKopia()[i]=(int)(rand()*(double)SortBI->GetLicznosc()/(double)RAND_MAX);
- SortBI->GetDaneKopia()[i]=stringi[rand()%15];
- }
- memcpy(SortBI->GetDane(),SortBI->GetDaneKopia(),SortBI->GetLicznosc()*sizeof(BiData));
- // delete stringi;
- }
- /******************************************************************************/
- void CleanUp(){ //sprzatanie po programie
- if(SortINT) delete(SortINT);
- if(SortBI) delete(SortBI);
- };
- /******************************************************************************/
- int main(){
- Ekran=true;
- // Ekran=false;
- Srand=257304;
- FactorM=20;
- // Licznosc=33;
- int tab[]={30};
- //int tab[]={5000,10000,30000, 50000, 100000,200000, 350000, 500000, 750000,1000000 };
- //int tab[]={10,30,30,100,300,3000,6000,10000,30000};
- try{
- for(int i=0;i<1; i++)
- {
- printf("==============================================\n");
- printf("TWOJA KANUSIOWA LICZBA NA DZIS TO %d \n", tab[i]);
- printf("=============================================\n", tab[i]);
- Licznosc=tab[i];
- InitINT();
- SortINT->BadanieAlgorytmow();
- // InitBI();
- // SortBI->BadanieAlgorytmow();
- }
- }
- // try{
- // InitINT();
- // SortINT->BadanieAlgorytmow();
- //
- //// InitBI();
- //// SortBI->BadanieAlgorytmow();
- // }
- catch(Except e){Error(e);}
- getchar();
- CleanUp();
- return 1;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement