Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- const int arraysize = 8000;
- int numcompares, numcopies;
- void swapem(double a, double b)
- {
- double temp;
- temp = a;
- a = b;
- b = temp;
- }
- void bubblesort(double r[], int n)
- {
- int j, i;
- for (j = 0; j < n - 1; j++)
- {
- for (i = 0; i < n - 1; i++)
- {
- numcompares++;
- if (r[i] > r[i + 1])
- {
- swapem(r[i], r[i + 1]);
- numcopies += 3;
- }
- }
- }
- }
- void printem(double r[])
- {
- cout << r[1000] << ", " << r[2000] << ", " << r[3000] << ", " <<
- r[4000] << ", " << r[5000] << ", " << r[6000] << ", " << r[7000] << ", " << r[7999] << endl;
- }
- int main()
- {
- ifstream inf("data.dat");
- ofstream outf("sorted.ot");
- string sortname;
- double arraynums[arraysize];
- for (int i = 0; i < arraysize; i++)
- {
- inf >> arraynums[i];
- }
- bubblesort(arraynums, arraysize);
- system("pause");
- return 0;
- }
- void printem(double r[], int n)
- {
- int i;
- for (i = 0; i < n; i++)
- cout << r[i]<< ", ";
- }
- printem(arraynums,20); // in main
- for (int i = 0; i < 10; i++)
- {
- cout << arraynums[i] << endl;
- }
- 41275.4
- 12113.1
- 50676
- 7662.34
- 50688.3
- -7926.28
- 13672.8
- -3212.9
- -13046.5
- -16798
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement