j4ggi

lab10_wybieranie

Dec 2nd, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5.  
  6. void SelectionSort(int* tab, int rozmiar)
  7. {
  8.     int i,j;
  9.      for(i=0;i<rozmiar-1;i++)
  10.      {
  11.       for(j=i;j<rozmiar;j++)
  12.              if(tab[j]<tab[i])
  13.              {
  14.              int a=tab[j];
  15.              tab[j]=tab[i];
  16.              tab[i]=a;
  17.              }
  18.      }
  19. }
  20.  
  21. void main()
  22. {
  23.     const int SIZE=100000;
  24.     int * tab=malloc(SIZE*sizeof(int));
  25.     int i;
  26.     srand(time(0));
  27.     for (i=0;i<SIZE;i++)
  28.         tab[i]=rand()%SIZE+1;
  29.     printf("100 elementow przed posortowaniem tablicy %i elementow:\n", SIZE);
  30.     for(i=0;i<SIZE;i+=SIZE/100)
  31.             printf("%i ", tab[i]);
  32.     int x=time(0);
  33.     printf("\nSortowanie start!\n");
  34.     SelectionSort(tab, SIZE);
  35.     int y=time(0);
  36.     printf("\nStop!\nCzas: %i sekund\n",y-x);
  37.     printf("100 elementow po posortowaniu tablicy %i elementow:\n", SIZE);
  38.     for(i=0;i<SIZE;i+=SIZE/100)
  39.             printf("%i ", tab[i]);
  40.     getchar();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment