Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. int arr[20001];
  5.  
  6. void insertion(int arr[],int n)
  7. {
  8. int i,j,t,temp;
  9. arr[0] = -999;
  10.  
  11. for(j=2; j<=n; j++){
  12. i=j-1;
  13. t=arr[j];
  14.  
  15. while(t<arr[i]){
  16. temp=arr[i];
  17. arr[i]=arr[i+1];
  18. arr[i+1]=temp;
  19.  
  20. i=i-1;
  21. }
  22. arr[i+1]=t;
  23. }
  24.  
  25. }
  26. void cpy()
  27. {
  28.  
  29. int j,n;
  30.  
  31. scanf("%d",&n);
  32.  
  33. for(j=1; j<=n; j++)
  34. {
  35. arr[j] = rand()%101;
  36. printf("%d ",arr[j]);
  37. }
  38.  
  39. }
  40. int main()
  41. {
  42. int n,m;
  43. clock_t begin,end;
  44. begin=clock();
  45. cpy();
  46. end=clock();
  47.  
  48. double time=(double)(end-begin)/CLOCKS_PER_SEC;
  49.  
  50. insertion(arr,n);
  51.  
  52.  
  53. printf("\nsorted array is:\n");
  54. for(m=1; m<=n; m++)
  55. printf("%d\n", arr[m]);
  56.  
  57. printf("Elapsed time for copy: %lf",time);
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement