Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <windows.h>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. unsigned long const int n= 200000;
  8. void bsort(unsigned long int n, float * a)
  9. {
  10. unsigned long int l, k;
  11. float p;
  12. l = n;
  13. do
  14. {
  15. k = 0;
  16. l = l - 1;
  17. for (unsigned long int i = 1; i < 1; i++)
  18. {
  19. if (a[i] < a[i + 1])
  20. {
  21. if (a[i] > a[i + 1])
  22. {
  23. p = a[i]; a[i] = a[i + 1]; a[i + 1] = p; k = k + 1;
  24. }
  25.  
  26. }
  27.  
  28. }
  29. while (k != 0);
  30.  
  31. }
  32. while (k != 0);
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38. float * a = new float[n];
  39. unsigned long int m;
  40. int k;
  41. time_t t;
  42. clock_t tp,tk;
  43. double tc;
  44. srand((unsigned)time(&t));
  45.  
  46. do
  47. {
  48. cout << "podaj ilość wyrazów ciągu"; cin >> m;
  49. cout << "ciąg wylosowany" << "\n";
  50. for (unsigned long int i = 1; i <= m; i++)
  51. {
  52. a[i] = rand() % 10000;
  53. cout<<a[i]<<" \t";
  54.  
  55. }
  56. cout << "\n";
  57.  
  58. {
  59. cout << "metoda bąbelkowa";
  60. tp = clock();
  61. bsort(m, a);
  62. tk = clock(); tc = (tk - tp) / double(CLOCKS_PER_SEC);
  63. cout << "czas obliczeń= " << tc << " \n";
  64. }
  65. cout << "ciąg posortowany" << " \n";
  66. for (unsigned long int i = 1; i <= m; i++)
  67. {
  68. cout << a[i] << "\t";
  69. }
  70. cin >> k;
  71. } while (k != 0);
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement