Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.70 KB | None | 0 0
  1. /******************************************************************************/
  2. /*                               AISD-Lab.2                                   */
  3. /******************************************************************************/
  4. /*  Grzegorz Janczyk                                                          */
  5. /*  Instytut Mikroelektroniki i Optoelektroniki                               */
  6. /*  Politechnika Warszawska                                                   */
  7. /*  ul. Koszykowa 75                                                          */
  8. /*  00-662 WARSZAWA                                                           */
  9. /*  tel. (+48)(22) 660 72 07                                                  */
  10. /*  www.imio.pw.edu.pl                                                        */
  11. /******************************************************************************/
  12.  
  13. #define _MAIN_CPP_
  14. #include "main.h"
  15. #include "dane.h"
  16. #include "sortowanie.h"
  17.  
  18. /******************************************************************************/
  19. /************** inicjalizacja/sprzatanie/generacja INT ************************/
  20. /******************************************************************************/
  21.  
  22. void InitINT(){ //inicjalizacja programowych struktur danych
  23.   srand(Srand);
  24.   SortINT = new AlgorytmySortowaniaINT(Licznosc);
  25.   if(!SortINT)throw ERR_Object;
  26.  
  27.   //WypelnijINT_1();
  28.   WypelnijINT_1();
  29. /*
  30.     SortINT->GetDaneKopia()[0] =9;
  31.     SortINT->GetDaneKopia()[1] =7;
  32.     SortINT->GetDaneKopia()[2] =5;
  33.     SortINT->GetDaneKopia()[3] =8;
  34.     SortINT->GetDaneKopia()[4] =8;
  35.     SortINT->GetDaneKopia()[5] =8;
  36.     SortINT->GetDaneKopia()[6] =7;
  37.     SortINT->GetDaneKopia()[7] =3;
  38.     SortINT->GetDaneKopia()[8] =11;
  39.     SortINT->GetDaneKopia()[9] =1;
  40.   memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
  41. */
  42.  
  43.   SortINT->WypiszStanNaEkran(Ekran);
  44.   if(Ekran){
  45.     printf("Zbior poczatkowy\n");
  46.     printf("\n************************\n");
  47.   }
  48.   SortINT->ZapiszStanDoPliku((char*)"Start");
  49. };
  50.  
  51. void WypelnijINT_1(){ //pesymistyczny
  52.     int a = Licznosc-1;
  53. int i;
  54.   for(i=0;i<SortINT->GetLicznosc();i++){
  55.  
  56.     SortINT->GetDaneKopia()[a] = i;
  57.     a = a - 1;
  58.   memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
  59.   }
  60.  
  61. }
  62.  
  63. void WypelnijINT_2(){
  64. double x1, x2, w, y1, y2;
  65.   for(int i=0;i<SortINT->GetLicznosc();i++){
  66.     do{
  67.       x1=2.0*rand()/RAND_MAX-1.0;
  68.       x2=2.0*rand()/RAND_MAX-1.0;
  69.       w=x1*x1+x2*x2;
  70.     }while(w>=1.0);
  71.     w=sqrt((-2.0*log(w))/w);
  72.     y1=x1*w;
  73.     y2=x2*w;
  74.     SortINT->GetDaneKopia()[i]=abs((int)(y2-y1));
  75.   }
  76.   memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
  77. }
  78.  
  79. void WypelnijINT_3(){
  80.   for(int i=0;i<SortINT->GetLicznosc();i++){
  81. /******************************************************************************/
  82. //int tablica[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  83. SortINT->GetDaneKopia()[i] = i;
  84.  
  85.  
  86. /******************************************************************************/
  87.   }
  88.   memcpy(SortINT->GetDane(),SortINT->GetDaneKopia(),SortINT->GetLicznosc()*sizeof(int));
  89. }
  90.  
  91. /******************************************************************************/
  92. /************** inicjalizacja/sprzatanie/generacja BI *************************/
  93. /******************************************************************************/
  94.  
  95. void InitBI(){ //inicjalizacja programowych struktur danych
  96.   srand(Srand);
  97.   SortBI = new AlgorytmySortowaniaBI(Licznosc);
  98.   if(!SortBI) throw ERR_Object;
  99.   WypelnijBI_1();
  100.  
  101.   SortBI->WypiszStanNaEkran(Ekran);
  102.   if(Ekran){
  103.     printf("Zbior poczatkowy\n");
  104.     printf("\n************************\n");
  105.   }
  106.   SortBI->ZapiszStanDoPliku((char*)"Start");
  107. };
  108.  
  109. void WypelnijBI_1(){ // rozklad normalny
  110. int i;
  111. //char (*stringi)[16]=new char[16][16];
  112. char stringi[16][16];
  113.  
  114.   strcpy(stringi[0],"A");
  115.   strcpy(stringi[1],"B");
  116.   strcpy(stringi[2],"C");
  117.   strcpy(stringi[3],"D");
  118.   strcpy(stringi[4],"E");
  119.   strcpy(stringi[5],"F");
  120.   strcpy(stringi[6],"G");
  121.   strcpy(stringi[7],"H");
  122.   strcpy(stringi[8],"J");
  123.   strcpy(stringi[9],"K");
  124.   strcpy(stringi[10],"L");
  125.   strcpy(stringi[11],"M");
  126.   strcpy(stringi[12],"N");
  127.   strcpy(stringi[13],"P");
  128.   strcpy(stringi[14],"R");
  129.   strcpy(stringi[15],"S");
  130.  
  131.   for(i=0;i<SortBI->GetLicznosc();i++){
  132.     SortBI->GetDaneKopia()[i]=(int)(rand()*(double)SortBI->GetLicznosc()/(double)RAND_MAX);
  133.     SortBI->GetDaneKopia()[i]=stringi[rand()%15];
  134.   }
  135.   memcpy(SortBI->GetDane(),SortBI->GetDaneKopia(),SortBI->GetLicznosc()*sizeof(BiData));
  136. //  delete stringi;
  137. }
  138.  
  139. /******************************************************************************/
  140.  
  141. void CleanUp(){  //sprzatanie po programie
  142.   if(SortINT) delete(SortINT);
  143.   if(SortBI)  delete(SortBI);
  144. };
  145.  
  146. /******************************************************************************/
  147.  
  148. int main(){
  149.   Ekran=true;
  150. //  Ekran=false;
  151.  
  152.   Srand=257304;
  153.   FactorM=20;
  154.  // Licznosc=33;
  155.     int tab[]={30};
  156.     //int tab[]={5000,10000,30000, 50000, 100000,200000, 350000, 500000, 750000,1000000 };
  157.     //int tab[]={10,30,30,100,300,3000,6000,10000,30000};
  158.   try{
  159.     for(int i=0;i<1; i++)
  160.         {
  161.         printf("==============================================\n");
  162.            printf("TWOJA KANUSIOWA LICZBA NA DZIS TO    %d    \n", tab[i]);
  163.            printf("=============================================\n", tab[i]);
  164.     Licznosc=tab[i];
  165.     InitINT();
  166.     SortINT->BadanieAlgorytmow();
  167.  
  168.  
  169. //    InitBI();
  170. //    SortBI->BadanieAlgorytmow();
  171. }
  172.   }
  173.  
  174.  
  175. //  try{
  176. //    InitINT();
  177. //    SortINT->BadanieAlgorytmow();
  178. //
  179. ////    InitBI();
  180. ////    SortBI->BadanieAlgorytmow();
  181. //  }
  182.   catch(Except e){Error(e);}
  183.   getchar();
  184.   CleanUp();
  185.   return 1;
  186. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement