Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void SelectionSort(int* tab, int rozmiar)
- {
- int i,j;
- for(i=0;i<rozmiar-1;i++)
- {
- for(j=i;j<rozmiar;j++)
- if(tab[j]<tab[i])
- {
- int a=tab[j];
- tab[j]=tab[i];
- tab[i]=a;
- }
- }
- }
- void main()
- {
- const int SIZE=100000;
- int * tab=malloc(SIZE*sizeof(int));
- int i;
- srand(time(0));
- for (i=0;i<SIZE;i++)
- tab[i]=rand()%SIZE+1;
- printf("100 elementow przed posortowaniem tablicy %i elementow:\n", SIZE);
- for(i=0;i<SIZE;i+=SIZE/100)
- printf("%i ", tab[i]);
- int x=time(0);
- printf("\nSortowanie start!\n");
- SelectionSort(tab, SIZE);
- int y=time(0);
- printf("\nStop!\nCzas: %i sekund\n",y-x);
- printf("100 elementow po posortowaniu tablicy %i elementow:\n", SIZE);
- for(i=0;i<SIZE;i+=SIZE/100)
- printf("%i ", tab[i]);
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment