Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cmath>
  5. #include <iomanip>
  6. using namespace std;
  7. const int arraysize = 8000;
  8. int numcompares, numcopies;
  9. void swapem(double a, double b)
  10. {
  11. double temp;
  12. temp = a;
  13. a = b;
  14. b = temp;
  15. }
  16. void bubblesort(double r[], int n)
  17. {
  18. int j, i;
  19. for (j = 0; j < n - 1; j++)
  20. {
  21. for (i = 0; i < n - 1; i++)
  22. {
  23. numcompares++;
  24. if (r[i] > r[i + 1])
  25. {
  26. swapem(r[i], r[i + 1]);
  27. numcopies += 3;
  28. }
  29. }
  30. }
  31. }
  32. void printem(double r[])
  33. {
  34. cout << r[1000] << ", " << r[2000] << ", " << r[3000] << ", " <<
  35. r[4000] << ", " << r[5000] << ", " << r[6000] << ", " << r[7000] << ", " << r[7999] << endl;
  36. }
  37. int main()
  38. {
  39. ifstream inf("data.dat");
  40. ofstream outf("sorted.ot");
  41. string sortname;
  42. double arraynums[arraysize];
  43. for (int i = 0; i < arraysize; i++)
  44. {
  45. inf >> arraynums[i];
  46. }
  47. bubblesort(arraynums, arraysize);
  48. system("pause");
  49. return 0;
  50. }
  51.  
  52. void printem(double r[], int n)
  53. {
  54. int i;
  55. for (i = 0; i < n; i++)
  56. cout << r[i]<< ", ";
  57. }
  58. printem(arraynums,20); // in main
  59.  
  60. for (int i = 0; i < 10; i++)
  61. {
  62. cout << arraynums[i] << endl;
  63. }
  64.  
  65. 41275.4
  66. 12113.1
  67. 50676
  68. 7662.34
  69. 50688.3
  70. -7926.28
  71. 13672.8
  72. -3212.9
  73. -13046.5
  74. -16798
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement