Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void InsertionSort(int* tab, int rozmiar)
- {
- int i,j;
- for (i = 1; i < rozmiar; i++)
- for(j = i; j-1 >= 0 && tab[j]<tab[j-1]; j--)
- {int a=tab[j];
- tab[j]=tab[j-1];
- tab[j-1]=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");
- InsertionSort(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