Advertisement
alexarcan

Lab1_DSA

Oct 9th, 2014
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. #include <time.h>
  7.  
  8. float aux;
  9. void starton(void)
  10. {
  11.     aux = clock();
  12.  
  13. }
  14. float startoff(void)
  15. {
  16.     return(clock() - aux) / CLK_TCK;
  17. }
  18.  
  19. void functie_test()
  20. {
  21.     int i,j,k;
  22.     for(i=1;i<=200000;i++)
  23.         for(j=1;j<=20000;j++)
  24.             if(i%2)
  25.                 k=i;
  26. }
  27.  
  28. void bublesort(int a[], int N) //sortare crescatoare
  29. {
  30.     int i, j, temp;
  31.     for (i = 0; i<N; i++)
  32.         for (j = N - 1; j>i; j--)
  33.  
  34.             {
  35.                   if (a[j - 1]>a[j])
  36.                     {
  37.                         temp = a[j - 1];
  38.                         a[j - 1] = a[j];
  39.                         a[j] = temp;
  40.                     }
  41.             }
  42. }
  43. void array(int a[], int N)
  44. {
  45.  
  46.     for (int i = 0; i < N; i++)
  47.         a[i] = N - i;
  48.    
  49. }
  50.  
  51. void main(void)
  52. {
  53.     float timp;
  54.     //generate_a();
  55.      
  56.     //functie_test();
  57.     int  N = 12000, a[12000];
  58.     array(a, N);
  59.  
  60.     starton();
  61.  
  62.     bublesort(a, N);
  63.  
  64.     timp = startoff();
  65.     printf("The execution time is: %f",timp);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement