Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include<time.h>
  6. void wybieranie(int a[], int n)
  7. {
  8. int k, x;
  9. int ilosc = 0;
  10. for (int i = 0; i < n - 1; i++)
  11. {
  12. k = i;
  13. x = a[i];
  14. for (int j = i + 1; j < n; j++)
  15. if (a[j] < x)
  16. {
  17. k = j;
  18. x = a[j];
  19. }
  20. ilosc++;
  21. a[k] = a[i];
  22. a[i] = x;
  23. }
  24. std::cout << "[Wybieranie] Ilosc porownian " << ilosc << std::endl;
  25. }
  26.  
  27. void wstawianie(int a[], int n)
  28. {
  29. int j, x;
  30. int ilosc = 0;
  31. int ilosc_while = 0;
  32. int i = 0;
  33. for (i = 1; i < n; i++)
  34. {
  35. x = a[i];
  36. j = i - 1;
  37. while (j >= 0 && x < a[j])
  38. {
  39. a[j + 1] = a[j];
  40. j--;
  41. ilosc_while++;
  42. }
  43. a[j + 1] = x;
  44. ilosc++;
  45. }
  46. double l = (1 / i) + 1;
  47. std::cout << "[Wstawienie]LSR :" << l << std::endl;
  48. std::cout << "[Wstawienie]N = :" << ilosc << std::endl;
  49. std::cout << "[Wstawienie]Ilosc porownian w petli while " <<ilosc_while << std::endl;
  50. }
  51.  
  52.  
  53. int main()
  54. {
  55. int tab[1000];
  56. srand(time(0));
  57.  
  58. for (int i = 0; i < 1000; i++)
  59. tab[i] = rand();
  60.  
  61. int j = 0;
  62. int k = 0;
  63. long n = 1000;
  64. wybieranie(tab, n);
  65. wstawianie(tab, n);
  66. int pes = ((n - 1) * n) / 2;
  67. std::cout << "Pesymistyczna " << pes << std::endl;
  68.  
  69. _getch();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement